var jsw={
		OBJECT_INDEX:0
};
var Short={
	MAX_VALUE:99999
};
var Integer={
	MAX_VALUE:99999
};
jsw.DEBUG_DOM=null;
jsw.DEBUG_DOM_PANEL=null;
jsw.debugEnabled=false;
jsw.isDebugEnabled=function(){
	return jsw.debugEnabled;
};
jsw.debug=function (obj,methodName,str){
	if(!jsw.isDebugEnabled()) return;
	if(jsw.DEBUG_DOM_PANEL==null){
		
		jsw.DEBUG_DOM_PANEL=document.createElement('div');
		var style=jsw.DEBUG_DOM_PANEL.style;
		style.position="absolute";
		style.zIndex=900;
		style.overflow="hidden";
		style.top=document.body.clientHeight-300+"px";
		style.left='0px';
		style.height="300px";
		style.width="500px";
		//style.border="2px solid #c0c0c0";
		
		jsw.DEBUG_DOM=document.createElement('textarea');
		style=jsw.DEBUG_DOM.style;
		style.position="absolute";
		style.color="#c0c0c0";
		style.backgroundColor="black";
		style.zIndex=900;
		//style.overflow="auto";
		style.left='0px';
		style.height="270px";
		style.width="500px";
		jsw.DEBUG_DOM_PANEL.appendChild(jsw.DEBUG_DOM);
		document.body.appendChild(jsw.DEBUG_DOM_PANEL);
		//document.body.appendChild(jsw.DEBUG_DOM);
		var hideButton=document.createElement('input');
		hideButton.style.position="absolute";
		hideButton.style.top="272px";
		hideButton.type="button";
		hideButton.value="hide debug window";
		hideButton.onclick=function(){
			jsw.DEBUG_DOM_PANEL.style.display="none";
		};
		var debugButton=document.createElement('input');
		debugButton.style.position="absolute";
		debugButton.style.top="272px";
		debugButton.style.left="200px";
		debugButton.type="button";
		debugButton.value="print BODY HTML";
		debugButton.onclick=function(){
			jsw.debug(document.body.innerHTML);
		};
		
		jsw.DEBUG_DOM_PANEL.appendChild(hideButton);
		jsw.DEBUG_DOM_PANEL.appendChild(debugButton);
	}
	var msg=[];
	if(arguments.length==1){
		msg.push(obj);
	}
	else{
		if(methodName!=null){
			var classname;
			if(typeof obj.getClassName == 'function'){
				classname=obj.getClassName();
			}else{
				classname="unknow-class";
			}
			msg.push(classname)
			msg.push(".");
			msg.push(methodName);
			msg.push("()");
		}
		if(str!=null){
			msg.push(str);
		}
	}
	msg.push("\n");
	var sm=msg.join('');
	jsw.DEBUG_DOM.value += sm;
	status=jsw.DEBUG_DOM_PANEL.scrollTop;
	//jsw.DEBUG_DOM_PANEL.scrollTop=jsw.DEBUG_DOM_PANEL.scrollHeight-jsw.DEBUG_DOM_PANEL.clientHeight;
	jsw.DEBUG_DOM_PANEL.style.display="";
	
	//var win=window.open("","_blank");
	//win.document.write(a);
	//return a;
}

//-- EventQueue --
jsw.EventQueue=function(){
		
};

jsw.EventQueue.prototype={
		queues:[],
		invokeLater:function(runnable) {
				//todo: 
		//		jsw.systemEventQueue.postEvent(
				//		new InvocationEvent(Toolkit.getDefaultToolkit(), runnable));
		},
		postEvent:function(theEvent) {
				//todo:
				//SunToolkit.flushPendingEvents();
				//postEventPrivate(theEvent);
		}
};
jsw.systemEventQueue=new jsw.EventQueue();
//-- Toolkit --
jsw.Toolkit=function(){};
jsw.Toolkit.systemEventQueueImpl=jsw.systemEventQueue;
jsw.Toolkit.getEventQueue=function(){
		return systemEventQueueImpl;
};
//-- EventDispatchThread --
jsw.EventDispatchThread=function(){
};
jsw.EventDispatchThread.prototype={
		run:function(){
				//todo: pumpEvents
		}
};

//-- Repaintmanager --
jsw.RepaintManager=function(){
};
jsw.RepaintManager.prototype={
		dirtyComponents:{},
		invalidComponents:null,
		addDirtyRegion:function(c,x,y,w,h){
				if ((w <= 0) || (h <= 0) || (c == null)) {
						return;
				}
				if ((c.getWidth() <= 0) || (c.getHeight() <= 0)) {
						return;
				}
				if (this.extendDirtyRegion(c, x, y, w, h)) {
						// Component was already marked as dirty, region has been
						// extended, no need to continue.
						return;
				}
				var root = null;
				for (var p = c; p != null; p = p.getParent()) {
						if (!p.isVisible()) {
								return;
						}
						if ((p.isWindow())) {
								//if (p instanceof Frame &&
								//				(((Frame)p).getExtendedState() & Frame.ICONIFIED) ==
								//										Frame.ICONIFIED) {
								//		return;
								//}
						root = p;
						break;
						}
				}
				if (root == null) return;
				//if (this.extendDirtyRegion(c, x, y, w, h)) {
				//				// In between last check and this check another thread
				//				// queued up runnable, can bail here.
				//				return;
				//}
				//JDK: this.dirtyComponents.put(c, new Rectangle(x, y, w, h));
				this.dirtyComponents[c.hashCode()]={x:x,y:y,width:w,height:h};
				//SystemEventQueueUtilities.queueComponentWorkRequest(root);
				
		},
		
		extendDirtyRegion:function(c, x, y, w, h){
				var r = this.dirtyComponents[c.hashCode()];
				if(r!=null){
						return true;
				}
				return false;
		},
		
		addInvalidComponent:function(invalidComponent){
				var validateRoot = null;
				for(var c = invalidComponent; c != null; c = c.getParent()) {
						if (c.isCellRendererPane() ) {
								return;
						}
						if (c.isValidateRoot()) {
								validateRoot = c;
								break;
						}
				}
				if (validateRoot == null) {
						return;
				}
				var root = null;
				for(var c = validateRoot; c != null; c = c.getParent()) {
						if (!c.isVisible()) {
						return;
						}
						if ((c instanceof Window) || (c instanceof Applet)) {
						root = c;
						break;
						}
				}
				if (root == null) {
						return;
				}
				if (this.invalidComponents == null) {
						this.invalidComponents = [];
				}
				else {
						var n = this.invalidComponents.length;
						for(var i = 0; i < n; i++) {
						if(validateRoot == this.invalidComponents[i]) {
								return;
						}
						}
				}
				this.invalidComponents.push(validateRoot);
		},
		validateInvalidComponent:function(c){
				var ic;
				
				if(this.invalidComponents == null) {
						return;
				}
				ic = invalidComponents;
				//this.invalidComponents = null;
				
				var n = ic.length;
				for(var i = 0; i < n; i++) {
					ic[i].validate();
				}
				ic.splice(0,ic.length);
		},
		paintDirtyRegions:function(c){
				c.paint();
		}
};



//--WebRepaintManager--
jsw.WebRepaintManager=function(){};
jsw.WebRepaintManager.prototype={
		addDirtyRegion:function(c, dirtyAttrs){
				
				//todo open following segment, 'cuz currently web component doesn't have size
				//if ((c.getWidth() <= 0) || (c.getHeight() <= 0)) {
				//		return;
				//}
				var root = null;
				for (var p = c; p != null; p = p.getParent()) {
						if (!p.isVisible()) {
						return;
						}
						if (p.isWindow()) {
						// Iconified frames are still visible!
						//if (p instanceof Frame &&
						//		(((Frame)p).getExtendedState() & Frame.ICONIFIED) ==
						//						Frame.ICONIFIED) {
						//		return;
						//}
						root = p;
						break;
						}
				}
				if (root == null) return;
				this.paintDirtyRegion(c, dirtyAttrs);
		},
		addInvalidComponent:function(invalidComponent){
				var validateRoot = null;
				for(var c = invalidComponent; c != null; c = c.getParent()) {
						if (c.isCellRendererPane() ) {
								return;
						}
						if (c.isValidateRoot()) {
								validateRoot = c;
								break;
						}
				}
				if (validateRoot == null) {
						return;
				}
				this.validateInvalidComponent(validateRoot);
		},
		validateInvalidComponent:function(c){
				c.validate();
		},
		paintDirtyRegion:function(c, dirtyAttrs){
				c.paintImmediately(dirtyAttrs);
		}
		
};
//-- static RepaintManager instance --
jsw.RepaintManager.instance=new jsw.WebRepaintManager();
jsw.RepaintManager.currentManager=function(component){
		return jsw.RepaintManager.instance;
};
//-- SwingConstants
jsw.SwingConstants={};
jsw.SwingConstants.CENTER  = 0;
jsw.SwingConstants.TOP     = 1;
jsw.SwingConstants.LEFT    = 2;
jsw.SwingConstants.BOTTOM  = 3;
jsw.SwingConstants.RIGHT   = 4;
jsw.SwingConstants.NORTH      = 1;
jsw.SwingConstants.NORTH_EAST = 2;
jsw.SwingConstants.EAST       = 3;
jsw.SwingConstants.SOUTH_EAST = 4;
jsw.SwingConstants.SOUTH      = 5;
jsw.SwingConstants.SOUTH_WEST = 6;
jsw.SwingConstants.WEST       = 7;
jsw.SwingConstants.NORTH_WEST = 8;
jsw.SwingConstants.HORIZONTAL = 0;
jsw.SwingConstants.VERTICAL   = 1; 
jsw.SwingConstants.LEADING  = 10;
jsw.SwingConstants.TRAILING = 11;
jsw.SwingConstants.NEXT = 12;
jsw.SwingConstants.PREVIOUS = 13;

//-----------ComponentOrientation
jsw.JComponentOrientation=function(value){
	this.orientation = value;
};
jsw.JComponentOrientation.UNK_BIT	  = 1;
jsw.JComponentOrientation.HORIZ_BIT	= 2;
jsw.JComponentOrientation.LTR_BIT	  = 4;

jsw.JComponentOrientation.prototype={
	orientation:0,
	isHorizontal:function(){
		return (this.orientation & jsw.JComponentOrientation.HORIZ_BIT) != 0;
	},
	isLeftToRight:function(){
		return (this.orientation & jsw.JComponentOrientation.LTR_BIT) != 0;
	},
	getOrientation:function(locale){
		//Todo: localization i18n
		return LEFT_TO_RIGHT;
	}
};
jsw.JComponentOrientation.LEFT_TO_RIGHT= new jsw.JComponentOrientation(jsw.JComponentOrientation.HORIZ_BIT|jsw.JComponentOrientation.LTR_BIT);
jsw.JComponentOrientation.RIGHT_TO_LEFT=new jsw.JComponentOrientation(jsw.JComponentOrientation.HORIZ_BIT);
jsw.JComponentOrientation.UNKNOWN=new jsw.JComponentOrientation(
	jsw.JComponentOrientation.HORIZ_BIT|
	jsw.JComponentOrientation.LTR_BIT|
	jsw.JComponentOrientation.UNK_BIT);
//-- ComponentUI --
jsw.JComponentUI=function(){
};
jsw.JComponentUI.prototype={
	installUI:function(component){
	},
	uninstallUI:function(component){
	},
	paint:function(c){
	},
	update:function(c){
		if (c.isOpaque()) {
			c.getWrapperDom().style.backgroundColor=c.getBackground();
		}
		this.paint(c);
	},
	getPreferredSize:function(c){return null;},
	getMinimumSize:function(c){return this.getPreferredSize(c);},
	getMaximumSize:function(c){return this.getPreferredSize(c);},
	contains:function(c,x,y){return c.inside(x,y);},
	
	getBaseline:function(c, width, height){
		if (c == null) {
			throw "Component must be non-null";
		}
		if (width < 0 || height < 0) {
			throw "Width and height must be >= 0";
		}
		return -1;
	},
	getBaselineResizeBehavior:function(c){
		//Todo:
	},
	getAccessibleChildrenCount:function(c){
		//todo:
	},
	getAccessibleChild:function(c,i){
		//todo:
	}
};
jsw.plaf={
		basic:{}
};

//-- BasicComponentUI --
jsw.plaf.basic.BasicComponentUI=function(){
	jsw.plaf.basic.BasicComponentUI.superclass.constructor.apply(this,arguments);
};
Ext.extend(jsw.plaf.basic.BasicComponentUI, jsw.JComponentUI,{
	getMinimumSize:function(c){
			var insets = c.getInsets();
			var miniSize;
			var border=c.getBorder();
			if(border!=null){
					miniSize=border.getMinimumPaintSize();
			}else{
					var insets=c.getInsets();
					miniSize={
							width:insets.left+insets.right,
							height:insets.top+insets.bottom
					};
					//every component must have a miniSize that larger
					// than zero, otherwise BoxLayout would work wrong,
					// it would set alignment to 0
					if(miniSize.width==0){
						miniSize.width=5;
					}
					if(miniSize.height==0){
						miniSize.height=5;
					}
			}
			var dx = miniSize.width;
			var dy = miniSize.height;
			var padding = c.getPadding();
			dx+=padding.left+padding.right;
			dy+=padding.top+padding.bottom;
			return {width:dx,height:dy};
	}
	
	
				//getPreferredSize:function(c){
				//		jsw.plaf.basic.BasicComponentUI.superclass.getPreferredSize.call(this,c);
				//		
				//}
});


jsw.plaf.basic.BasicComponentUI.instance=new jsw.plaf.basic.BasicComponentUI();



//-- BasicLabelUI --
jsw.plaf.basic.BasicLabelUI=function(){
	jsw.plaf.basic.BasicLabelUI.superclass.constructor.call(this);
};
jsw.plaf.basic.BasicLabelUI.testDom=null;
Ext.extend(jsw.plaf.basic.BasicLabelUI,jsw.plaf.basic.BasicComponentUI,
{
	getMinimumSize:function(c) {
		var d = this.getPreferredSize(c);
		d.width = jsw.plaf.basic.BasicLabelUI.superclass.getMinimumSize.apply(this,arguments).width;
		return d;
	},
	getMaximumSize:function(c){
		var d = this.getPreferredSize(c);
		d.width=Integer.MAX_VALUE;
		//d.width = jsw.plaf.basic.BasicLabelUI.superclass.getMaximumSize.apply(this,arguments).width;
		return d;
	},
	getPreferredSize:function(c){
				var border=c.getBorder();
				var miniSize;
				if(border!=null){
						miniSize=border.getMinimumPaintSize();
				}else{
						var insets=c.getInsets();
						miniSize={
								width:insets.left+insets.right,
								height:insets.top+insets.bottom
						};
				}
				var dx = miniSize.width;
				var dy = miniSize.height;
		//var insets = c.getInsets();
		//
		//var dx = insets.left + insets.right;
		//var dy = insets.top + insets.bottom;
		
		//if(!Ext.isIE){
			var padding = c.getPadding();
			dx+=padding.left+padding.right;
			dy+=padding.top+padding.bottom;
		//}
		var testDiv=jsw.plaf.basic.BasicLabelUI.testDom;
		var text=c.getText();
		if(text==null ||text.length==0){
			text="1";
		}
		if(testDiv==null){
			testDiv=document.createElement("font");
			testDiv.style.position="absolute";
			testDiv.style.zIndex="-190";
			testDiv.style.visibility="hidden";
			document.body.appendChild(testDiv);
			jsw.plaf.basic.BasicLabelUI.testDom=testDiv;
		}
		if(text!=null){
			testDiv.innerHTML=text;
			var dim={width:dx+testDiv.clientWidth
			,height:dy+testDiv.clientHeight};
			return dim;
		}else{
			return {width:dx,height:dy};
		}
	}
});
jsw.plaf.basic.BasicLabelUI.instance=new jsw.plaf.basic.BasicLabelUI();

jsw.UIManager={
	
	getUI:function(target){
		
	}
};
//-- interface LayoutManager --
jsw.LayoutManager=function(){
};
jsw.LayoutManager.prototype=
{
		addLayoutComponent:function(name, comp){
		},
		removeLayoutComponent:function(comp){
		},
		preferredLayoutSize:function(parent){},
		minimumLayoutSize:function(parent){},
		layoutContainer:function(parent){}
};
//-- interface LayoutManager2 --
jsw.LayoutManager2=function(){
}
Ext.extend(jsw.LayoutManager2, jsw.LayoutManager,
{
	   isLayoutManager2:true,
		addLayoutComponent:function(comp, constraints){
		},
		maximumLayoutSize:function(target){
				
		},
		getLayoutAlignmentX:function(target){},
		getLayoutAlignmentY:function(target){},
		invalidateLayout:function(target){}
});
//-- interface border.Border --
jsw.border={};
jsw.border.AbstractBorder=function(){};
jsw.border.AbstractBorder.prototype={
		paintBorder:function(c, dom){},
		getBorderInsets:function(c){return {top:0,left:0,right:0,bottom:0};},
		isBorderOpaque:function(){return false;},
		
		//especially for web UI
		getMinimumPaintSize:function(){
				var is= this.getBorderInsets();
				return {width:is.left+is.right, height:is.top+is.bottom};
		}
};

jsw.JComponentPeer=function(){};
jsw.JComponentPeer.SET_LOCATION = 1;
jsw.JComponentPeer.SET_SIZE = 2;
jsw.JComponentPeer.SET_BOUNDS = 3;
jsw.JComponentPeer.SET_CLIENT_SIZE = 4;
jsw.JComponentPeer.RESET_OPERATION = 5;
jsw.JComponentPeer.NO_EMBEDDED_CHECK = (1 << 14);
jsw.JComponentPeer.DEFAULT_OPERATION = jsw.JComponentPeerSET_BOUNDS;
//-- BaseWebComponent
jsw.BaseWebComponent=function(){
		this.padding={top:0,left:0,right:0,bottom:0};
		this._objectIndex_=jsw.OBJECT_INDEX;
		jsw.OBJECT_INDEX++;
		jsw.BaseWebComponent.register[this.hashCode()]=this;
		this.ui=jsw.plaf.basic.BasicComponentUI.instance;
		this.domEventRegistered=false;
		this.mouseEventHandler=new Function("e","jsw.event.DomElementEventHandle.handleMouseEvent(e,'"+this.hashCode()+"');");
};
jsw.BaseWebComponent.register={};
jsw.BaseWebComponent.getRegisteredComp=function(hashcode){
   
	
	return jsw.BaseWebComponent.register[hashcode];
};
jsw.BaseWebComponent.prototype={
//Ext.extend(jsw.BaseWebComponent, Ext.Container,{
		wrapperDom:null,
		childrenWrapper:null,
		contentDom:null,
		hashCode:function(){
			if(this._hashCode==null){				
				this._hashCode=this.getClassName()+this._objectIndex_;
			}
			return this._hashCode;
		},
		getClassName:function(){
			return "jsw.BaseWebComponent";
		},
		setPadding:function(insets){/**@param insets {left:,right:,top:,bottom:}*/
			this.padding=insets;
		},
		getPadding:function(insets){
			if(insets==null)
				insets={};
			for(var o in this.padding)
				insets[o]=this.padding[o];
			return insets;
		},
		getWrapperDom:function(){
			return this.wrapperDom;
		},
		//@Override
		destory:function(){
				this.removeNotify();				
				jsw.BaseWebComponent.superclass.destory.apply(this,arguments);
		},
		
		isWindow:function(){
				return false;
		},
		
		isCellRendererPane:function(){
				return false;
		},
		registerDomEventHandler:function(){
			if(this.domEventRegistered){
				return;
			}
			this.domEventRegistered=true;
			if(this.mouseListeners.length>0){
					if(this.wrapperDom.onclick==null ){
						this.wrapperDom.onclick=this.mouseEventHandler;
					}
					if(this.wrapperDom.oncontextmenu==null ){
						this.wrapperDom.oncontextmenu=this.mouseEventHandler;
					}
					if(this.wrapperDom.ondblclick==null){
						this.wrapperDom.ondblclick=this.mouseEventHandler;
					}
					if(this.wrapperDom.onmousedown==null ){
						this.wrapperDom.onmousedown=this.mouseEventHandler;
					}
					if(this.wrapperDom.onmouseup==null){
						this.wrapperDom.onmouseup=this.mouseEventHandler;
					}
					if(this.wrapperDom.onmouseover==null){
						this.wrapperDom.onmouseover=this.mouseEventHandler;
					}
					if(this.wrapperDom.onmouseout==null){
						this.wrapperDom.onmouseout=this.mouseEventHandler;
					}
				}
		},
		removeChildDom:function(childComp){
			if(this.childrenWrapper==null)
				this.childrenWrapper=this.wrapperDom;
			this.childrenWrapper.removeChild(childComp.wrapperDom);
			delete childComp.wrapperDom;
		},
		addNotify:function(){
			
		},
		
		removeNotify:function(){
		   
		},
		destory:function(){
			 jsw.BaseWebComponent.register[this.hashCode()]=null;
			delete jsw.BaseWebComponent.register[this.hashCode()];
		}
};

//-- Component --
jsw.JComponent = function(){
		jsw.JComponent.superclass.constructor.call(this,{autoEl:'div'});
		
		this.component=[];
		this.boundsOp = jsw.JComponentPeer.DEFAULT_OPERATION;
		this.foreground=null;
		
		this.mouseListeners=[];
		
};

//jsw.JComponent.POSITION_CHANGED="pos";

jsw.JComponent.IS_DOUBLE_BUFFERED					   =  0;
jsw.JComponent.ANCESTOR_USING_BUFFER					=  1;
jsw.JComponent.IS_PAINTING_TILE						 =  2;
jsw.JComponent.IS_OPAQUE								=  3;
jsw.JComponent.KEY_EVENTS_ENABLED					   =  4;
jsw.JComponent.FOCUS_INPUTMAP_CREATED				   =  5;
jsw.JComponent.ANCESTOR_INPUTMAP_CREATED				=  6;
jsw.JComponent.WIF_INPUTMAP_CREATED					 =  7;
jsw.JComponent.ACTIONMAP_CREATED						=  8;
jsw.JComponent.CREATED_DOUBLE_BUFFER					=  9;
jsw.JComponent.IS_PRINTING							  = 11;
jsw.JComponent.IS_PRINTING_ALL						  = 12;
jsw.JComponent.IS_REPAINTING							= 13;
jsw.JComponent.WRITE_OBJ_COUNTER_FIRST				  = 14;
jsw.JComponent.RESERVED_1							   = 15;
jsw.JComponent.RESERVED_2							   = 16;
jsw.JComponent.RESERVED_3							   = 17;
jsw.JComponent.RESERVED_4							   = 18;
jsw.JComponent.RESERVED_5							   = 19;
jsw.JComponent.RESERVED_6							   = 20;
jsw.JComponent.WRITE_OBJ_COUNTER_LAST				   = 21;
jsw.JComponent.REQUEST_FOCUS_DISABLED				   = 22;
jsw.JComponent.INHERITS_POPUP_MENU					  = 23;
jsw.JComponent.OPAQUE_SET							   = 24;
jsw.JComponent.AUTOSCROLLS_SET						  = 25;
jsw.JComponent.FOCUS_TRAVERSAL_KEYS_FORWARD_SET		 = 26;
jsw.JComponent.FOCUS_TRAVERSAL_KEYS_BACKWARD_SET		= 27;

jsw.JComponent.TOP_ALIGNMENT=0.0;
jsw.JComponent.CENTER_ALIGNMENT=0.5;
jsw.JComponent.BOTTOM_ALIGNMENT=1.0;
jsw.JComponent.LEFT_ALIGNMENT=0.0;
jsw.JComponent.RIGHT_ALIGNMENT=1.0;

Ext.extend(jsw.JComponent, jsw.BaseWebComponent,{
		_x:0,
		_y:0,
		width:0,//we don't hope it override the 'width' in ExtJs
		height:0,
		border:null,
		validateRoot:false,
		layoutMgr:null,
		visible:true,
		valid:false,
		prefSize:null,
		minSize:null,
		maxSize:null,
		minSizeSet:false,
		background:null,
		backgroundImg:null,
		paintingChild:null,
		ui:null,
		flags:0,
		rendered:false,
		component:null,
		parent:null,
		isAlignmentYSet:false,
		alignmentY:0,
		isAlignmentXSet:false,
		alignmentX:0,
		componentOrientation:jsw.JComponentOrientation.UNKNOWN,
		
		
		getComponentOrientation:function(){
			return this.componentOrientation;
		},
		
		setAlignmentY:function(alignmentY) {
			this.alignmentY = alignmentY > 1.0 ? 1.0 : alignmentY < 0.0 ? 0.0 : alignmentY;
			this.isAlignmentYSet = true;
		},
		getAlignmentY:function() {
			if (this.isAlignmentYSet) {
				return this.alignmentY;
			}
			var yAlign;
			if (this.layoutMgr!=null && this.layoutMgr.isLayoutManager2) {
				var lm = this.layoutMgr;
				yAlign = lm.getLayoutAlignmentY(this);
			} else {
				yAlign = jsw.JComponent.CENTER_ALIGNMENT;
			}
			return yAlign;
		},
		
		setAlignmentX:function(alignmentX) {
			this.alignmentX = alignmentX > 1.0 ? 1.0 : alignmentX < 0.0 ? 0.0 : alignmentX;
			this.isAlignmentXSet = true;
		},
		
		getAlignmentX:function() {
			if (this.isAlignmentXSet) {
				return this.alignmentX;
			}
			var xAlign;
			if (this.layoutMgr!=null && this.layoutMgr.isLayoutManager2) {
					var lm = this.layoutMgr;
					xAlign = lm.getLayoutAlignmentX(this);
			} else {
				xAlign = jsw.JComponent.CENTER_ALIGNMENT;
			}
			return xAlign;
		},
		
		_setFlag:function(aFlag, aValue) {
			if(aValue) {
				this.flags |= (1 << aFlag);
			} else {
				this.flags &= ~(1 << aFlag);
			}
		},
		
		_getFlag:function(aFlag) {
			var mask = (1 << aFlag);
			return ((this.flags & mask) == mask);
		},
		
		setPaintingChild:function(paintingChild) {
			this.paintingChild = paintingChild;
		},
		
		isOpaque:function() {
			return this._getFlag(jsw.JComponent.IS_OPAQUE);
		},
		
		setOpaque:function(isOpaque) {
			var oldValue = this._getFlag(jsw.JComponent.IS_OPAQUE);
			this._setFlag(jsw.JComponent.IS_OPAQUE, isOpaque);
			this._setFlag(jsw.JComponent.OPAQUE_SET, true);
			this._firePropertyChange("opaque", oldValue, isOpaque);
		},
		
		
		
		getWidth:function(){
				return this.width;
		},
		
		getHeight:function(){
				return this.height;
		},
		
		getSize:function(){
				return {width:this.width, height:this.height};
		},
		
		setPreferredSize:function(preferredSize){
				var old;
				if (this.prefSizeSet) {
						old = this.prefSize;
				}
				else {
						old = null;
				}
				this.prefSize = preferredSize;
				this.prefSizeSet = (preferredSize != null);
				this._firePropertyChange("preferredSize", old, preferredSize);
		},
		
		isPreferredSizeSet:function() { 
				return this.prefSizeSet;
		},
		
		getPreferredSize:function(){with(this){
				if (this.isPreferredSizeSet()) {
						var dim = this.prefSize;
						if (dim == null) {
								this.prefSize = (this.layoutMgr != null) ?this.layoutMgr.preferredLayoutSize(this):this.getMinimumSize();
								
								dim = this.prefSize;
						}
						return (dim!=null)?{width:dim.width, height:dim.height}:null;
				}
				
				var size = null;
				if (this.ui != null) {
						size = this.ui.getPreferredSize(this);
				}
				//return (size != null) ? size : super.getMinimumSize();
				if(size == null){
						var dim = this.prefSize;
						if (dim == null || !this.isValid()) {
							//if(jsw.isDebugEnabled()){
							//	jsw.debug(this,"getPreferredSize",this.layoutMgr.constructor);
							//}
							this.prefSize = (this.layoutMgr != null) ?this.layoutMgr.preferredLayoutSize(this):this.getMinimumSize();
							dim = this.prefSize;
						}
						size ={width:dim.width, height:dim.height};
				}
				
				return size;
		}},
		_maximumSize:function(){
				var dim = this.maxSize;
				if (dim == null || !(this.isMaximumSizeSet() || this.isValid())) {
						if(this.layoutMgr!=null && typeof(this.layoutMgr.maximumLayoutSize)=="function"){
								this.maxSize=this.layoutMgr.maximumLayoutSize(this);
						}else{
								this.maxSize={width:99999, height:99999};
						}
						dim = this.maxSize;
				}
				//return super.getMaximumSize();
				if(dim!=null)
						return {width:dim.width, height:dim.height};
				else
					return dim;
		},
		getMaximumSize:function() {
				var size = null;
				if (this.isMaximumSizeSet()) {
						return this._maximumSize();
				}				
				if (this.ui != null) {
						size = this.ui.getMaximumSize(this);
				}
				return (size!=null)?size:this._maximumSize();
		},
		
		setMaximumSize:function(maximumSize){
				var old;
				if (this.maxSizeSet) {
						old = this.maxSize;
				}
				else {
						old = null;
				}
				this.maxSize = maximumSize;
				this.maxSizeSet = (maximumSize != null);
				this._firePropertyChange("maximumSize", old, maximumSize);
		},
		
		isMaximumSizeSet:function() { 
				return this.maxSizeSet;
		},
		
		setMinimumSize:function(minimumSize){
				 var old;
				if (this.minSizeSet) {
						old = this.minSize;
				}
				else {
						old = null;
				}
				this.minSize = minimumSize;
				this.minSizeSet = (minimumSize != null);
				this._firePropertyChange("minimumSize", old, minimumSize);
		},
		
		isMinimumSizeSet:function(){
				return this.minSizeSet;
		},
		_minimumSize:function(){
				var dim = this.minSize;
				if(dim ==null||!(this.isMinimumSizeSet()|| this.isValid())){
						this.minSize=(this.layoutMgr!=null)?this.layoutMgr.minimumLayoutSize(this):this.getSize();
						dim=this.minSize;
				}
				if (dim != null){
						return {width:dim.width, height:dim.height};
				}
				else{
					return dim;
				}
		},
		
		getMinimumSize:function() {
				if (this.isMinimumSizeSet()) {
						return this._minimumSize();
				}
				var size = null;
				if (this.ui != null) {
						size = this.ui.getMinimumSize(this);
				}
				return (size != null) ? size : this._minimumSize();
		},
		revalidate:function(){
				if (this.getParent() == null) {				
						return;
				}
				//jsw.debug(this,"revalidate");
				this.invalidate();
				var rpmgr=jsw.RepaintManager.currentManager(this);
				rpmgr.addInvalidComponent(this);
		},
		
		invalidate:function(){
			var layoutMgr = this.layoutMgr;
				if (layoutMgr!=null && layoutMgr.isLayoutManager2) {
					
					layoutMgr.invalidateLayout(this);
				}
				this.valid = false;
				if (!this.isPreferredSizeSet()) {
						this.prefSize = null;
				}
				if (!this.isMinimumSizeSet()) {
						this.minSize = null;
				}
				if (!this.isMaximumSizeSet()) {
						this.maxSize = null;
				}
				//if (this.getParent() != null)
					//jsw.debug(this.getClassName()+".invalidate() parent="+this.getParent());
					if (this.getParent() != null)
						//jsw.debug("parent.valid:"+this.getParent().valid);
				if (this.getParent() != null && this.getParent().valid) {
					
						this.parent.invalidate();
				}
		},
		
		isValid:function() {
				return this.valid;
		},
		//@param dirtyAttrs if it is null, 
		//it implies all is dirty, need to render the whole component
		repaint:function(dirtyAttrs){
				var rpmgr=jsw.RepaintManager.currentManager(this);
				rpmgr.addDirtyRegion(this, dirtyAttrs);
		},
		
		validate:function(){
			//jsw.debug(this,"validate","this.valid= "+this.valid);
				if (!this.valid) {
						this._validateTree();
						this.valid = true;
						//jsw.debug(this,"validate","* set this.valid true ");
				}
		},
		
		_validateTree:function(){
			//jsw.debug(this.getClassName()+"._validateTree()");
			this.doLayout();
			var cn=this.getComponentCount();
			for(var i=0;i<cn;i++){
				if(!this.component[i].valid)
					this.component[i]._validateTree();
			}
			this.valid = true;
		},
		getComponentCount:function(){
				return this.component.length;
		},
		doLayout:function(){
				var layoutMgr = this.layoutMgr;
				if (layoutMgr != null) {
							
						layoutMgr.layoutContainer(this);
				}
		},
		
		paintImmediately:function(dirtyAttrs){
				this.paint(dirtyAttrs);
		},
		
		paint:function(dirtyAttrs){
			with(this){
				if(this.width==0||this.height==0)
					return;
				if(!this.rendered){
						this.wrapperDom=document.createElement("div");
						this.wrapperDom.id="wrapperDom-"+this.hashCode();						
						this.parent.childrenWrapper.appendChild(this.wrapperDom);
						this.contentDom=this.wrapperDom;//default situation
						this.wrapperDom.style.position="absolute";
						this.wrapperDom.style.overflow="hidden";
						
				}
				if(jsw.isDebugEnabled()){
					jsw.debug(this,"paint","this.size="+this.width+", "+this.height);
					jsw.debug(this,"paint",this.hashCode()+" x="+this._x+", y="+this._y);
				}
				var style=this.wrapperDom.style;
				
				style.left=this._x+"px";
				
				style.top=this._y+"px";
				style.width=this.width+"px";
				style.height=this.height+"px";
				
				if(this.foreground!=null){
					style.color=this.foreground;
				}
				if(!this.rendered){
					this.childrenWrapper=this.wrapperDom;//default situation
				}
				//var bCreateSubDoms=(!this.rendered && this.getBorder()!=null);
				if(!this.rendered && this.getBorder()!=null){
					this.contentDom=document.createElement("div");
					this.contentDom.style.position="absolute";
					this.contentDom.style.overflow="hidden";
					this.contentDom.id="contentDom-"+this.hashCode();
					this.wrapperDom.appendChild(this.contentDom);
					
					//this.childrenWrapper=document.createElement("div");
					//this.childrenWrapper.style.position="absolute";
					//this.childrenWrapper.style.overflow="hidden";
					//this.childrenWrapper.id="childrenWrapper-"+this.hashCode();
					//this.wrapperDom.appendChild(this.childrenWrapper);
				}
				//----- contentDom style --
				var contentWidth;
				var contentHeight;
				
				style=this.contentDom.style;
				if(this.wrapperDom!=this.contentDom){
					var insets=this.getInsets();
					
					style.left=insets.left+"px";
					style.top=insets.top+"px";
				
					if(!Ext.isIE){//firefox
						contentWidth=this.width-insets.right-insets.left-this.padding.left-this.padding.right;
						if(jsw.isDebugEnabled()){
							jsw.debug(this,"paint","contentWidth="+contentWidth+", this.width="+this.width);
						}
						contentHeight=this.height-insets.top-insets.bottom-this.padding.top-this.padding.bottom;
					}else{
						contentWidth=this.width-insets.right-insets.left;
						contentHeight=this.height-insets.top-insets.bottom;
					}
					style.width=contentWidth+"px";
					style.height=contentHeight+"px";
					//(this.constructor+"\n"+this.padding.left);
				}
				if(this.padding.left!=0)
						style.paddingLeft=this.padding.left;
				if(this.padding.top!=0)
					style.paddingTop=this.padding.top;
				if(this.padding.right!=0)
					style.paddingRight=this.padding.right;
				if(this.padding.bottom!=0)
					style.paddingBottom=this.padding.bottom;
				
				//----- contentDom style --
				style=this.childrenWrapper.style;
				//layoutMgr has caculated child location with insets size.
				if(this.wrapperDom!=this.childrenWrapper){
					var insets=this.getInsets();
					
					style.left="0px";
					style.top="0px";
					style.width=contentWidth+"px";
					style.height=contentHeight+"px";
					//(this.constructor+"\n"+this.padding.left);
				}
				this.registerDomEventHandler();
				this.paintComponent(this.contentDom,dirtyAttrs);
				if(dirtyAttrs!="location"){
					this._paintBorder(this.wrapperDom);
				// if it just changes size or location, no need to paint children
				
					this._paintChildren();
				}
				if(!this.renderred){
					if(this.cursor!=null){
						var cu=this.cursor;
						if(cu=='hand'){
							cu='pointer';
						}
						this.wrapperDom.style.cursor=cu;
					}					
				}
				if(jsw.isDebugEnabled()){
					jsw.debug(this,"paint","wrapperDom-left="+this.wrapperDom.style.left
						+", wrapperDom-top="+this.wrapperDom.style.top);
				}
				this.rendered=true;
			}
		},
		
		paintComponent:function(wrapperDom, dirtyAttrs){
				if(this.ui!=null){
					this.ui.update(this);
				}
		},
		
		_paintBorder:function(containerDom){
				var border = this.getBorder();
				if (border != null) {
						border.paintBorder(this, containerDom);
				}
		},
		
		_paintChildren:function(){
			var i = this.getComponentCount() - 1;
			if (i < 0) {
				return;
			}
			//if (this.paintingChild != null &&
			//	this.paintingChild.isOpaque()) {
			//	for (; i >= 0; i--) {
			//		if (this.getComponent(i) == paintingChild){
			//			break;
			//		}
			//	}
			//}
			for (; i >= 0 ; i--) {
				var comp = this.getComponent(i);
				if (comp != null &&(comp.isVisible() == true)) {
					//TODO: set color and font
					//cg.setColor(comp.getForeground());
					//cg.setFont(comp.getFont());
					if(jsw.isDebugEnabled()){
						jsw.debug(this,"_paintChildren",comp.hashCode());
					}
					comp.paint();
					
				}
			}
		},
		
		isValidateRoot:function(){
				return this.validateRoot;
		},
		
		getInsets:function(){
				if (this.border!= null) {
						return this.border.getBorderInsets(this);
				}
				return {top:0,left:0,right:0,bottom:0};
		},
		
		getParent:function(){
				return this.parent;
		},
		
		setLayout:function(mgr) {
				this.layoutMgr = mgr;
		},
		getBodrder:function(){
				return this.border;
		},
		setBorder:function(border) {
				var oldBorder = this.border;
				this.border = border;
				this._firePropertyChange("border", oldBorder, border);
				if (border != oldBorder) {
						if (border == null || oldBorder == null ||
								!(border.getBorderInsets(this).equals(oldBorder.getBorderInsets(this)))) {
								this.revalidate();
						} 
						this.repaint();
				}
		},
		getBorder:function(){
				return this.border;
		},
		//@Override
		setVisible:function(aFlag) {
				if(aFlag != this.isVisible()) {
						this.visible=aFlag;
						
						if(this.wrapperDom!=null){
							this.wrapperDom.style.display=aFlag?"":"none";
						}
						//this.repaint();
						if (this.parent != null) {
							this.parent.invalidate();
						}
						//jsw.JComponent.superclass.setVisible.call(this, aFlag);
						
						this.revalidate();
						
						this.repaint();		
				}
		},
		setBackgroundImg:function(url){
				this.backgroundImg=url;				
				this.repaint({backgdImg:true});
		},
		setForeground:function(color) {
			var oldColor = this.foreground;
			this.foreground = color;
			//if (peer != null) {
				//color = this.getForeground();
				//if (color != null) {
				//	peer.setForeground(c);
				//}
			//}
			// This is a bound property, so report the change to
			// any registered listeners.  (Cheap if there are none.)
			this._firePropertyChange("foreground", oldColor, color);
			this.repaint({foreground:true});
		},
		setBackground:function(colorStr){
				this.background=colorStr;
				this.repaint({backgdCl:true});
		},
		_remove:function(index){
			if (comp < 0  || comp >= this.component.length) {
					throw "ArrayIndexOutOfBoundsException: "+comp;
			}
			var comp = this.component[index];
			
			comp.removeNotify();
			comp.parent.removeChildDom(comp);
			if(this.layoutMgr != null) {
				this.layoutMgr.removeLayoutComponent(comp);
			}
			//adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, 
			//	-comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
			//adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
			//	-comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
			//adjustDescendants(-(comp.countHierarchyMembers()));
			
			comp.parent==null;
			this.component.splice(index,1);
			comp.wrapperDom.innerHTML="";
			comp.wrapperDom=null;
			comp.rendered=false;
			if (this.valid) {
				this.invalidate();
			}
			//Todo: containe event listener
			//if (this.containerListener != null ||
			//	(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
			//	Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
			//	ContainerEvent e = new ContainerEvent(this, 
			//						 ContainerEvent.COMPONENT_REMOVED,
			//						 comp);
			//	dispatchEvent(e);
			//}
			//comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
			//					   this, HierarchyEvent.PARENT_CHANGED,
			//					   Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
			//TODO: update cursor
			//if (peer != null && layoutMgr == null && isVisible()) {
			//	updateCursorImmediately();
			//}
		},
		remove:function(comp){
			if(typeof(comp)=="number"){
				this._remove(comp);
			}else{
				if (comp.parent == this)  {
					var index = -1;
					for(var i=0,l=this.component.length;i<l;i++){
						if(this.component[i] == comp){
							index = i;
							break;
						}
					}
					if (index >= 0) {
						this._remove(index);
					}
				}
			}
		},
		getComponent:function(i){
			return this.component[i];
		},
		//@Override
		add:function( comp) {
			this._addImpl(comp, null, -1);
			return comp;
		},
		_addImpl:function(comp, constraints, index){
			
			if (index > this.component.length || (index < 0 && index != -1)) {
				throw "illegal component position";
			}
			this._checkAddToSelf();
			//checkNotAWindow(comp);
			if (comp.parent != null) {
				comp.parent.remove(comp);
					if (index > this.component.length) {
						throw "illegal component position";
					}
			}
			//index == -1 means add to the end.
			if (index == -1 || index == this.component.length) {
				this.component.push(comp);
			}else if(index == 0){
				this.component.unshift(comp);
			}else {
				var tail=this.component.slice(index);
				this.component[index]=comp;
				var start=index+1;
				for(var i=0,l=tail.length;i<l;i++){
					this.component[start+i]=tail[i];
				}
				//JDK:component.add(index, comp);
			}
			comp.parent = this;
		   
			//adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, 
			//	comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
			//adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
				//comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
			//adjustDescendants(comp.countHierarchyMembers());

			if (this.valid) {
				this.invalidate();
			}
			
			//if (peer != null) {
				comp.addNotify();
			//}
			if (this.layoutMgr != null) {
				if (this.layoutMgr.isLayoutManager2) {
					this.layoutMgr.addLayoutComponent(comp, constraints);
				} else if (typeof(constraints)=="string") {
					this.layoutMgr.addLayoutComponent(constraints, comp);
				}
			}
			//Todo: container lister
			//if (this.containerListener != null || 
			//	(eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
			//	Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
			//	ContainerEvent e = new ContainerEvent(this, 
			//						 ContainerEvent.COMPONENT_ADDED,
			//						 comp);
			//	dispatchEvent(e);
			//}
			//comp.createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, comp,
				//					   this, HierarchyEvent.PARENT_CHANGED,
			//						   Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
			
			//if (peer != null && layoutMgr == null && isVisible()) {
			//	updateCursorImmediately();
			//}
		},
		_checkAddToSelf:function(comp){
				for (var cn = this; cn != null; cn=cn.parent) {
					if (cn == comp) {
						throw "adding container's parent to itself";
					}
				}
		},
		
		//@Override
		insert:function(i,c){
				jsw.JComponent.superclass.insert.apply(this,arguments);
				if(c.addNotify!=null)
						c.addNotify();
		},
		setCursor:function(strCursor) {
			this.cursor = strCursor;
			this.updateCursorImmediately();
		},
		updateCursorImmediately:function(){
			//alert(renderred+this.cursor);
			if(this.renderred){
				var cu=this.cursor;
				if(cu=='hand'){
					cu='pointer';
				}
				this.wrapperDom.style.cursor=cu;
			}
		},
		setBoundsOp:function(op) {
			if (op == jsw.JComponentPeer.RESET_OPERATION) {
				this.boundsOp = jsw.JComponentPeer.DEFAULT_OPERATION;
			} else 
				if (this.boundsOp == jsw.JComponentPeer.DEFAULT_OPERATION) {
					this.boundsOp = op;
				}			
		},
		getBoundsOp:function(){
			return this.boundsOp;
		},
		setLocation:function(x,y){
			this.setBoundsOp(jsw.JComponentPeer.SET_LOCATION);
			if(arguments.length>1)
				this.setBounds(x, y, this.width, this.height);
			else
				this.setBounds(arguments[0].x,arguments[0].y, this.width, this.height);
		},
		setSize:function(width, height){
			this.setBoundsOp(jsw.JComponentPeer.SET_SIZE);
			if(arguments.length==1){
				this.setBounds(this._x,this._y,arguments[0].width,arguments[0].height);
			}else{
				this.setBounds(this._x,this._y,width,height);
			}
		},
		setBounds:function(x, y, width, height){
				this.setBoundsOp(jsw.JComponentPeer.SET_BOUNDS);
				
				var resized = (this.width != width) || (this.height != height);
				var moved = (this._x != x) || (this._y != y);
				if (!resized && !moved) {
						return;
				}
				var oldX = this._x;
				var oldY = this._y;
				var oldWidth = this.width; 
				var oldHeight = this.height;
				this._x=x;
				this._y=y;
				this.width=width;
				this.height=height;
				
				if (resized) {
						this.isPacked = false;
						this.invalidate();
				}
				var needNotify = true;
				if (this.isWindow()) {
						needNotify = false;
				}
				if (parent != null && parent.valid) {
						parent.invalidate();
				}
				if (needNotify) {
						this._notifyNewBounds(resized, moved);
				}
				//JDK: it repaints the old bound of parent
				//this._repaintParentIfNeeded(oldX, oldY, oldWidth, oldHeight);
				this.repaint((moved && !resized)?"location":null);
				this.setBoundsOp(jsw.JComponentPeer.RESET_OPERATION);
		},
		getWidth:function(){
				return this.getSize().width;
		},
		getHeight:function(){
				return this.getSize().height;
		},
		
		isShowing:function() {
				if (this.visible) {
						var parent = this.getParent();
						return (parent == null) || parent.isShowing();
				}
				return false;
		},
		
		_repaintParentIfNeeded:function(oldX, oldY, oldWidth, oldHeight){
				//todo: resolve painting twice problem.
				if(this.getParent()!=null && this.isShowing()){
						//jdk:this.getParent().repaint(oldX, oldY, oldWidth, oldHeight);						
						//jdk:this.repaint();
						this.getParent().repaint();
						this.repaint();
				}
		},
		_notifyNewBounds:function(resized, moved){
				//todo: send resize event and move event
		},
		
		addNotify:function(){
			jsw.JComponent.superclass.addNotify.call(this);
		},
		
		removeNotify:function(){
			jsw.JComponent.superclass.removeNotify.call(this);
		},
		
		isVisible:function(){
				//@Override
				return this.visible;
		},
		_firePropertyChange:function(name,oldV,newV){
				//todo
		},
		addMouseListener:function( mouseListener) {
			if (mouseListener == null) {
				return;
			}
			if(this.mouseListeners==null){
				this.mouseListeners=[];
			}
			this.mouseListeners.push(mouseListener);
		},
		
		updateUI:function(){},
		
		setUI:function(newUI) {
        if (this.ui != null) {
            this.ui.uninstallUI(this);
            //clean UIClientPropertyKeys from client properties
            if (this.clientProperties != null) {
                //synchronized(this.clientProperties) {
				for(var key in this.clientProperties){
					this.clientProperties[key]=null;
					delete this.clientProperties[key];
				}
               // }
            }
        }
        //todo: implement UIManager
         this.aaTextInfo =
	     jsw.UIManager.getDefaults().get(SwingUtilities2.AA_TEXT_PROPERTY_KEY);
        var oldUI = this.ui;
        this.ui = newUI;
        if (this.ui != null) {
            this.ui.installUI(this);
        }

        this._firePropertyChange("UI", oldUI, newUI);
        this.revalidate();
        this.repaint();
    }
});

jsw.event={};
jsw.event.MouseListener=function(){
};
jsw.event.MouseListener.prototype={
	mouseClicked:function(mouseEvent){},
    mousePressed:function(mouseEvent){},
    mouseReleased:function(mouseEvent){},
    mouseEntered:function(mouseEvent){},
    mouseExited:function(mouseEvent){}
};
jsw.event.EventObject=function(source){
	this.source=source;
};
jsw.event.EventObject.prototype={
	getSource:function(){
		return this.source;
	}
};
jsw.event.AWTEvent=function(source,id){
	jsw.event.AWTEvent.superclass.constructor.call(this,source);
	this.id=id;
	this.id = id;
	//todo: open this comment
    //switch(id) {
    //  case ActionEvent.ACTION_PERFORMED:
    //  case ItemEvent.ITEM_STATE_CHANGED:
    //  case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED:
    //  case TextEvent.TEXT_VALUE_CHANGED:
    //    consumed = true;
    //    break;
    //  default:
    //}
};
Ext.extend(jsw.event.AWTEvent,jsw.event.EventObject,
{
	getId:function(){
		return this.id;
	},
	paramString:function() {
        return "";
    },
	consume:function(){
		with(this){
        switch(id) {
          case jsw.KeyEvent.KEY_PRESSED:
          case jsw.KeyEvent.KEY_RELEASED:
          case jsw.MouseEvent.MOUSE_PRESSED:
          case jsw.MouseEvent.MOUSE_RELEASED:
          case jsw.MouseEvent.MOUSE_MOVED:
          case jsw.MouseEvent.MOUSE_DRAGGED:
          case jsw.MouseEvent.MOUSE_ENTERED:
          case jsw.MouseEvent.MOUSE_EXITED:
          case jsw.MouseEvent.MOUSE_WHEEL:
          case jsw.InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
          case jsw.InputMethodEvent.CARET_POSITION_CHANGED:
              consumed = true;
              break;
          default:
              // event type cannot be consumed
        }
		}
    },
	isConsumed:function() {
        return this.consumed;
    },
	toString:function() {
		//todo:
        //var srcName = null;
        //if (source instanceof Component) {
        //    srcName = ((Component)source).getName();
        //} else if (source instanceof MenuComponent) {
        //    srcName = ((MenuComponent)source).getName();
        //}
		//return getClass().getName() + "[" + paramString() + "] on " +
        //    (srcName != null? srcName : source);
    }
});

//----- InputEvent ---------
jsw.event.InputEvent=function(source, id, when, modifiers){
	jsw.event.InputEvent.superclass.constructor.call(this,source,id);
	this.when=when;
	this.modifiers=modifiers;
	this.canAccessSystemClipboard = true;
};
Ext.extend(jsw.event.InputEvent, jsw.event.AWTEvent,{
		isShiftDown:function(){
			with(this){
				return (modifiers & SHIFT_MASK) != 0;
			}
		},
		isControlDown:function(){
		},
		isMetaDown:function(){
		},
		isAltDown:function(){
		},
		isAltGraphDown:function(){
		},
		getWhen:function(){
			return this.when;
		},
		getModifiers:function(){
			return this.modifiers & (JDK_1_3_MODIFIERS | HIGH_MODIFIERS);
		},
		consume:function() {
			this.consumed = true;
		},
		isConsumed:function() {
			return this.consumed;
		}
});
	
	
jsw.event.MouseEvent=function(source,id,when,modifiers,x,y,xAbs,yAbs,clickCount,popupTrigger,button){
	jsw.event.MouseEvent.superclass.constructor.call(this,source,id,when,modifiers);
	
	this.x=x;
	this.y = y;
    this.xAbs = xAbs;
    this.yAbs = yAbs;
    this.clickCount = clickCount;
    this.popupTrigger = popupTrigger;
};
Ext.extend(jsw.event.MouseEvent, jsw.event.InputEvent,{
		getXOnScreen:function() {
        return this.xAbs;
    },
	getYOnScreen:function() {
        return this.yAbs;
    },
	getLocationOnScreen:function(){
		return {x:xAbs, y:yAbs};
    },
	getX:function(){
		return this.x;
	},
	getY:function(){
		return this.y;
	},
	getPoint:function() {
		return {x:this.x, y:this.y};
    },
	translatePoint:function(x,y) {
        this.x += x;
        this.y += y;
    },
	getClickCount:function() {
        return this.clickCount;
    },
	getButton:function() {
		return this.button;
    },
	isPopupTrigger:function() {
        return this.popupTrigger;
    },
	paramString:function() {
		with(this){
        var str = [];

        switch(this.id) {
          case jsw.event.MouseEvent.MOUSE_PRESSED:
              str.push("MOUSE_PRESSED");
              break;
          case jsw.event.MouseEvent.MOUSE_RELEASED:
              str.push("MOUSE_RELEASED");
              break;
          case jsw.event.MouseEvent.MOUSE_CLICKED:
              str.push("MOUSE_CLICKED");
              break;
          case jsw.event.MouseEvent.MOUSE_ENTERED:
              str.push("MOUSE_ENTERED");
              break;
          case jsw.event.MouseEvent.MOUSE_EXITED:
              str.push("MOUSE_EXITED");
              break;
          case jsw.event.MouseEvent.MOUSE_MOVED:
              str.push("MOUSE_MOVED");
              break;
          case jsw.event.MouseEvent.MOUSE_DRAGGED:
              str.push("MOUSE_DRAGGED");
              break;
          case jsw.event.MouseEvent.MOUSE_WHEEL:
              str.push("MOUSE_WHEEL");
              break;
           default:
              str.push("unknown type");
        }
		
		str.push(",(").push(x).push(",").push(y).push(")"); 
        str.push(",absolute(").push(xAbs).push(",").push(yAbs).push(")"); 

        str.push(",button=").push(getButton());

        if (getModifiers() != 0) {
            str.push(",modifiers=").push(getMouseModifiersText(modifiers));
        }

        if (getModifiersEx() != 0) {
            str.push(",extModifiers=").push(getModifiersExText(modifiers));
        }

        str.push(",clickCount=").append(clickCount);
		return str.join("");
		}
	}
});
jsw.event.MouseEvent.MOUSE_FIRST= 500;
jsw.event.MouseEvent.MOUSE_LAST= 507;
jsw.event.MouseEvent.MOUSE_CLICKED = jsw.event.MouseEvent.MOUSE_FIRST;
jsw.event.MouseEvent.MOUSE_PRESSED = 1 + jsw.event.MouseEvent.MOUSE_FIRST;
jsw.event.MouseEvent.MOUSE_RELEASED = 2 + jsw.event.MouseEvent.MOUSE_FIRST;
jsw.event.MouseEvent.MOUSE_MOVED = 3 + jsw.event.MouseEvent.MOUSE_FIRST;
jsw.event.MouseEvent.MOUSE_ENTERED = 4 + jsw.event.MouseEvent.MOUSE_FIRST;
jsw.event.MouseEvent.MOUSE_EXITED = 5 + jsw.event.MouseEvent.MOUSE_FIRST;
jsw.event.MouseEvent.MOUSE_DRAGGED = 6 + jsw.event.MouseEvent.MOUSE_FIRST;
jsw.event.MouseEvent.MOUSE_WHEEL = 7 + jsw.event.MouseEvent.MOUSE_FIRST;
jsw.event.MouseEvent.NOBUTTON = 0;
jsw.event.MouseEvent.BUTTON1 = 1;
jsw.event.MouseEvent.BUTTON2 = 2;
jsw.event.MouseEvent.BUTTON3 = 3;

jsw.event.DomElementEventHandle={
	handleMouseEvent:function(e,hashcode){
		var comp=jsw.BaseWebComponent.getRegisteredComp(hashcode);
		var be= e||window.event;
		var id,popupTrigger,clickCount,button;
		var xAbs=be.clientX;
		var yAbs=be.clientY;
		var modifiers=0;
		var lisMethod;
		if(be.type=="mouseover"){
			id=jsw.event.MouseEvent.MOUSE_ENTERED;
			popupTrigger=false;
			clickCount=0;
			button = jsw.event.MouseEvent.BUTTON1;
			lisMethod="mouseEntered";
		}else if(be.type=="mouseout"){
			id=jsw.event.MouseEvent.MOUSE_EXITED;
			popupTrigger=false;
			clickCount=0;
			button = jsw.event.MouseEvent.BUTTON1;
			lisMethod="mouseExited";
		}else if(be.type=="mousedown"){
			id=jsw.event.MouseEvent.MOUSE_PRESSED;
			popupTrigger=false;
			clickCount=0;
			button = jsw.event.MouseEvent.BUTTON1;
			lisMethod="mousePressed";
		}else if(be.type=="mouseup"){
			id=jsw.event.MouseEvent.MOUSE_RELEASED;
			popupTrigger=false;
			clickCount=0;
			button = jsw.event.MouseEvent.BUTTON1;
			lisMethod="mouseReleased";
		}else if(be.type=="click"){
			id=jsw.event.MouseEvent.MOUSE_CLICKED;
			popupTrigger=false;
			clickCount=1;
			button = jsw.event.MouseEvent.BUTTON1;
			lisMethod="mouseClicked";
		}else if(be.type=="contextmenu"){
			id=jsw.event.MouseEvent.MOUSE_CLICKED;
			popupTrigger=true;
			clickCount=1;
			button = jsw.event.MouseEvent.BUTTON2;
		}else if(be.type=="dblclick"){
			id=jsw.event.MouseEvent.MOUSE_CLICKED;
			popupTrigger=false;
			clickCount=2;
			button = jsw.event.MouseEvent.BUTTON1;
			lisMethod="mouseClicked";
		}
		if(Ext.isIE){
			x=be.offsetX;
			y=be.offsetY;
			dom =be.srcElement;
		}else{
			switch(be.button){
			case 0:button=jsw.event.MouseEvent.BUTTON1;break;
			case 1:button=jsw.event.MouseEvent.BUTTON2;break;
			case 2:button=jsw.event.MouseEvent.BUTTON3;break;
			}
			var when=be.timestamp;
			x=be.layerX;
			y=be.layerY;
			dom =be.target;
		}
		var event = new jsw.event.MouseEvent(comp,id,when,modifiers,x,y,xAbs,yAbs,clickCount,popupTrigger,button);
		jsw.event.DomElementEventHandle.broadcastMouseEvent(event,comp,lisMethod);
	},
	broadcastMouseEvent:function(event, source,lisMethod){
		for(var i=0,l=source.mouseListeners.length;i<l;i++){
			eval("source.mouseListeners[i]."+lisMethod+"(event)");
		}
	}
};
jsw.JLabel=function(text){
		jsw.JLabel.superclass.constructor.call(this);
		if(text==null){
			text="";
		}
		this.setText(text);
		this.ui=jsw.plaf.basic.BasicLabelUI.instance;
		this.padding={top:2,left:3,right:5,bottom:2};
};

Ext.extend(jsw.JLabel, jsw.JComponent,
{
		TEXT_CHANGED:'text',
		getContentDom:function(){
			return this.contentDom;
		},
		
		setText:function(t){
				var oldValue = this.text;
				this.text = t;
				this._firePropertyChange("text", oldValue, t);
				if(t!=null){
						this.revalidate();
						this.repaint({TEXT_CHANGED:true});
				}
		},
		getText:function(){
				return this.text;
		},
		
		
		paintComponent:function(c,dirtyAttrs){
				
				if(dirtyAttrs==null
						||dirtyAttrs.backgdCl){
						if(this.background!=null && this.isOpaque())
							c.style.backgroundColor=this.background;
				}
				if(!this.isOpaque()){
					c.style.background="";
				}
				if( (dirtyAttrs == null
						||dirtyAttrs.backgdImg) && this.backgroundImg!=null && this.isOpaque()){
						
						if(Ext.isIE6){
								c.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='"+
										this.backgroundImg+"')";
						}
						else{
								c.style.backgroundImage="url("+this.backgroundImg+")";
						}
				}
				if(dirtyAttrs==null || dirtyAttrs.TEXT_CHANGED){
					c.innerHTML=this.getText();
				}
				return c;
		}
}
);

//@param url - image URL
//@param sizeRule - LOCK_WIDTH|LOCK_HEIGHT|NO_AUTO_SIZE
jsw.NetImgLabel=function(url,sizeRule,value){
	jsw.NetImgLabel.superclass.constructor.call(this);
	this.ui=jsw.plaf.basic.BasicComponentUI.instance;
	this.imageUrl=url;
	this.testImg=null;
	this.imageSize={width:-1,height:-1};	
	this.setPadding({left:0,right:0,top:0,bottom:0});
	//this.setPreferredSize({width:60,height:60});
	this.sizeRule=sizeRule;
	this.sizeValue=value;
	this.reload=true;
	
};
jsw.NetImgLabel.LOCK_WIDTH=1;
jsw.NetImgLabel.LOCK_HEIGHT=2;
jsw.NetImgLabel.NO_AUTO_SIZE=3;
jsw.NetImgLabel.AUTO_SIZE=4;
jsw.NetImgLabel.onTestImgLoad=function(evn){
	var e, src;
	if(Ext.isIE){
		e=window.event;
		src=e.srcElement;
	}else{
		e=evn;
		src=e.target;
	}	
	var _component=jsw.BaseWebComponent.getRegisteredComp(src.id.substring(8));
	var tmpsize={
		width:src.clientWidth,
			height:src.clientHeight
	};
	src.style.display="none";
	_component.reshapeImageSize(tmpsize);
};
Ext.extend(jsw.NetImgLabel,jsw.JLabel,{
		getClassName:function(){
			return "jsw.NetImgLabel";
		},
		setImageUrl:function(url){
			if(this.imageUrl!=url){
				this.imageUrl=url;
				this.loadImage(url);
			}
			
		},
		getImageUrl:function(){
			return this.imageUrl;
		},
		lockImageWidth:function(w){
			this.imageSize.width=w;
			this.unlockImageHeight();
			this.loadImage(this.imageUrl);
			//this.revalidate();
		},
	
		unlockImageWidth:function(){
			this.imageSize.width=-1;
			//this.revalidate();
		},
		lockImageHeight:function(h){
			this.imageSize.height=h;
			this.unlockImageWidth();
			this.loadImage(this.imageUrl);
			//this.revalidate();
		},
		
		unlockImageHeight:function(){
			this.imageSize.height=-1;
			//this.revalidate();
		},
		
		paintComponent:function(dom, dirtyAttrs){
			if(!this.rendered){
				var img=document.createElement("img");
				img.src="";
				img.style.padding="0px";
				img.style.margin="0px";
				dom.appendChild(img);
				this.imgDom=img;
				
			}
			if(dirtyAttrs!="location"){
				if(jsw.isDebugEnabled()){
					jsw.debug(this,"paintComponent",this.hashCode()+":"+this.width+","+this.height);
				}
				insets=this.getInsets();
				
				this.getImageDom().width=this.imageSize.width;
				this.getImageDom().height=this.imageSize.height;
			}
			if(this.imageReshaped){
				this.imageReshaped=false;
				//if(this.imageUrl!=this.getImageDom().src)
					this.getImageDom().src=this.imageUrl;
			}			
		},
		addNotify:function(){
			jsw.NetImgLabel.superclass.addNotify.call(this);
			if(this.reload){
				this.reload=false;
				jsw.debug(this,"addNotify","start to load "+this.hashCode());
			    if(this.sizeRule==null||this.sizeRule==jsw.NetImgLabel.AUTO_SIZE){
					this.loadImage(this.imageUrl);
			    }
			    else{
				    if(this.sizeRule==jsw.NetImgLabel.LOCK_WIDTH)
					    this.lockImageWidth(this.sizeValue);
				    else if(this.sizeRule==jsw.NetImgLabel.LOCK_HEIGHT)
					    this.lockImageHeight(this.sizeValue);
			    }
				
				jsw.debug(this,"addNotify","end to load");
			}
		},
		loadImage:function(url){
			
			
			if(this.testImg==null){
				this.testImg=document.createElement("img");
				this.testImg.id="imgTest-"+this.hashCode();
				this.testImg.style.visibility="hidden";
				this.testImg.style.zIndex=-192;
				this.testImg.onload=jsw.NetImgLabel.onTestImgLoad;
				document.body.appendChild(this.testImg);
			}
			this.testImg.style.display=""
			this.testImg.src=this.imageUrl;
		},
		getImageDom:function(){
			return this.imgDom;
		},
		reshapeImageSize:function(dim){
			//try{
			var size={};
			var insets=this.getInsets();
			
			if(this.imageSize.width!=-1){
				var scale=dim.width/dim.height;
				
				dim.width=Math.floor(this.imageSize.width);
				dim.height=Math.floor(this.imageSize.width/scale);
			}
			size.width=dim.width+insets.left+insets.right;
			size.height=dim.height+insets.top+insets.bottom;
			if(this.getBorder()!=null){
			    var minBorderSize=this.getBorder().getMinimumPaintSize();
			    size.width=Math.max(size.width, minBorderSize.width);
			    size.height=Math.max(size.height, minBorderSize.height);
			    //jsw.debug(this,"reshapeImageSize",this.hashCode()+":border-> "+minBorderSize.height);
			}
			if(jsw.isDebugEnabled()){
				jsw.debug(this,"reshapeImageSize",this.hashCode()+":"+size.width+","+size.height);
			}
			this.setPreferredSize(size);
			this.setMinimumSize(size);
			this.setMaximumSize(size);
			this.imageReshaped=true;
			this.imageSize.width=dim.width;
			this.imageSize.height=dim.height;
			//jsw.debug("reshapeImageSize");
			this.revalidate();
			this.repaint({reload:true});
			
			//}catch(e){
			//	alert(e.name + " "+ e.message);
			//}		
		},
		//@Overrider
		removeNotify:function(){
			if(this.testImg!=null){
				document.body.removeChild(this.testImg);
				this.testImg=null;
			}
			jsw.NetImgLabel.superclass.removeNotify.call(this);
		}
});

//-- Panel --
jsw.JPanel=function(layout){
	jsw.JPanel.superclass.constructor.apply(this,arguments);
	if(typeof(layout)=="undefined"){
				layout=new jsw.FlowLayout();
	}
	this.setLayout(layout);
	//setDoubleBuffered(isDoubleBuffered);
	//setUIProperty("opaque", Boolean.TRUE);
	if (!this._getFlag(jsw.JComponent.OPAQUE_SET)) {
		this.setOpaque(true);
		this._setFlag(jsw.JComponent.OPAQUE_SET, false);
	}
	this.maxSize={width:Integer.MAX_VALUE, height:Integer.MAX_VALUE};
	//this.setPreferredSize({width:300,height:200});
	//updateUI();
};
Ext.extend(jsw.JPanel, jsw.JComponent,
{
	getClassName:function(){
			return "jsw.JPanel";
		},
	paintComponent:function(wrapperDom,dirtyAttrs){		
		if(dirtyAttrs==null
				||dirtyAttrs["backgdCl"]){
				if(this.background!=null)
					wrapperDom.style.backgroundColor=this.background;
		}
		if( (dirtyAttrs == null
				||dirtyAttrs["backgdImg"]) && this.backgroundImg!=null){
				
				if(Ext.isIE6){
						wrapperDom.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='"+
								this.backgroundImg+"')";
				}
				else{
						wrapperDom.style.backgroundImage="url("+this.backgroundImg+")";
				}
		}
	}
});

jsw.HTMLPane=function(html){
	jsw.HTMLPane.superclass.constructor.call(this);
	this.ui=null;
	if(html==null){
		html="";
	}
	if(html!=null){
		this.setHTML(html);
	}
};
Ext.extend(jsw.HTMLPane, jsw.JPanel,{
		getClassName:function(){
			return "jsw.HTMLPane";
		},
		setHTML:function(text){
			//this.setText(text);
			this.htmlContent=text;
			this.revalidate();
			this.repaint({text:true});
		},
		paintComponent:function(dom,dirty){
			jsw.HTMLPane.superclass.paintComponent.apply(this,arguments);
			if(dirty==null || dirty.text){
				if(this.parent.getClassName()=="jsw.Viewport_0_"){
					this.wrapperDom.style.overflow="visible";
					if(this.wrapperDom!=this.contentDom){
						this.contentDom.style.overflow="visible";
					}
				}
				this.contentDom.innerHTML=this.htmlContent;
			}
		}
});

//-- ScrollPane --
jsw.ScrollPane=function(view, vsbPolicy, hsbPolicy){
		jsw.ScrollPane.superclass.constructor.call(this);
		if(typeof(vsbPolicy)=='undefined')
				vsbPolicy=jsw.ScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED;
		if(typeof(hsbPolicy)=='undefined')
				hsbPolicy=jsw.ScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
		with(this){
			this.viewport=new jsw.Viewport_0_();
			//this.viewport.setLayout(new jsw.BoxLayout(this.viewport,jsw.BoxLayout.X_AXIS));
			this.viewport.add(view);
			
			setVerticalScrollBarPolicy(vsbPolicy);
			setHorizontalScrollBarPolicy(hsbPolicy);
			setLayout(new jsw.BoxLayout(this,jsw.BoxLayout.X_AXIS));
			add(viewport);
			//setLayout(new jsw.FlowLayout(jsw.FlowLayout.CENTER,0,0));
		}
		
};
jsw.ScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED=20;
jsw.ScrollPane.VERTICAL_SCROLLBAR_NEVER = 21;
jsw.ScrollPane.VERTICAL_SCROLLBAR_ALWAYS = 22;
jsw.ScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED = 30;
jsw.ScrollPane.HORIZONTAL_SCROLLBAR_NEVER = 31;
jsw.ScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS = 32;
Ext.extend(jsw.ScrollPane, jsw.JPanel,{
		getClassName:function(){
			return "jsw.ScrollPane";
		},
		isValidateRoot:function() {
			return true;
		},
		setVerticalScrollBarPolicy:function(policy) {
			with(this){
				switch (policy) {
				case jsw.ScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED:
				case jsw.ScrollPane.VERTICAL_SCROLLBAR_NEVER:
				case jsw.ScrollPane.VERTICAL_SCROLLBAR_ALWAYS:
						break;
				default:
						throw "invalid verticalScrollBarPolicy";
				}
				var old = this.verticalScrollBarPolicy;
				this.verticalScrollBarPolicy = policy;
				_firePropertyChange("verticalScrollBarPolicy", old, policy);
				revalidate();
				repaint();
			}
		},
	setHorizontalScrollBarPolicy:function(policy) {
		with(this){
			
			switch (policy) {
			case jsw.ScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED:
			case jsw.ScrollPane.HORIZONTAL_SCROLLBAR_NEVER:
			case jsw.ScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS:
				break;
			default:
				throw "invalid horizontalScrollBarPolicy";
			}
			var old = this.horizontalScrollBarPolicy;
			this.horizontalScrollBarPolicy = policy;
			_firePropertyChange("horizontalScrollBarPolicy", old, policy);
			revalidate();
			repaint();
		}
    },
	paintComponent:function(wrapperDom,dirtyAttrs){
		jsw.ScrollPane.superclass.paintComponent.apply(this,arguments);
		//if(this.rendered) return;		
	}
});

jsw.Viewport_0_=function(){
	jsw.Viewport_0_.superclass.constructor.call(this);
	//this.setLayout(new jsw.BoxLayout(this,jsw.BoxLayout.X_AXIS));
	this.setLayout(null);
};
Ext.extend(jsw.Viewport_0_, jsw.JPanel,{
		getClassName:function(){
			return "jsw.Viewport_0_";
		},
		isValidateRoot:function() {
			return true;
		},
	paintComponent:function(dom,d){
		with(this.parent){
		if(horizontalScrollBarPolicy==jsw.ScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED){
			this.wrapperDom.style.overflowX='auto';
		}else if(horizontalScrollBarPolicy==jsw.ScrollPane.HORIZONTAL_SCROLLBAR_NEVER){
			this.wrapperDom.style.overflowX='hidden';
		}else if(horizontalScrollBarPolicy==jsw.ScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS){
			this.wrapperDom.style.overflowX='scroll';
		}
		jsw.debug(this,"paintComponent",verticalScrollBarPolicy+"=="+jsw.ScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		if(verticalScrollBarPolicy==jsw.ScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED){
			
			this.wrapperDom.style.overflowY='auto';
			jsw.debug(this,"paintComponent",this.childrenWrapper.style.overflow);
		}else if(horizontalScrollBarPolicy==jsw.ScrollPane.VERTICAL_SCROLLBAR_NEVER){
			this.wrapperDom.style.overflowY='hidden';
		}else if(horizontalScrollBarPolicy==jsw.ScrollPane.VERTICAL_SCROLLBAR_ALWAYS){
			this.wrapperDom.style.overflowY='scroll';
		}
		}
	},
	doLayout:function(){
		var s=this.getComponent(0).getPreferredSize();
		s.width=Math.max(this.width, s.width);
		s.height=Math.max(this.height, s.height);
		this.getComponent(0).setBounds(0,0,s.width,s.height);
	}
});

//--- JSplitPane --
jsw.JSplitPane=function(){
	this.orientation=0;
	continuousLayout=false;
	leftComponent=null;
	rightComponent=null;
	dividerSize=0;
	dividerSizeSet = false;
	oneTouchExpandable=false;
	oneTouchExpandableSet=false;
	lastDividerLocation=0;
	resizeWeight=0.0;
	dividerLocation=0;
	
};
jsw.JSplitPane.VERTICAL_SPLIT=0;
jsw.JSplitPane.HORIZONTAL_SPLIT=1;
jsw.JSplitPane.LEFT='left';
jsw.JSplitPane.RIGHT='right';
jsw.JSplitPane.TOP = "top";
jsw.JSplitPane.BOTTOM = "bottom";
jsw.JSplitPane.DIVIDER = "divider";
jsw.JSplitPane.ORIENTATION_PROPERTY="orientation";
jsw.JSplitPane.DIVIDER_SIZE_PROPERTY = "dividerSize";
jsw.JSplitPane.ONE_TOUCH_EXPANDABLE_PROPERTY = "oneTouchExpandable";
jsw.JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY ="lastDividerLocation";
jsw.JSplitPane.DIVIDER_LOCATION_PROPERTY = "dividerLocation";
jsw.JSplitPane.RESIZE_WEIGHT_PROPERTY = "resizeWeight";

Ext.extend(jsw.JSplitPane,jsw.JComponent,{
		
});
//-- BrowserDocument --
jsw.BrowserDocument=function(){
		jsw.BrowserDocument.superclass.constructor.apply(this,arguments);
		
		this.wrapperDom=document.body;
		this.childrenWrapper=this.wrapperDom;
		this._x=0;
		this._y=0;
		this.width=document.body.clientWidth;
		this.height=document.body.clientHeight;
		this.setLayout(new jsw.FlowLayout());
		document.body.scroll='no';
		document.body.topMargin=0;
		document.body.bottomMargin=0;
		document.body.leftMargin=0;
		document.body.rightMargin=0;
		window.onresize=jsw.BrowserDocument._fireResize;
};
jsw.BrowserDocument._fireResize=function(){
	jsw.BrowserDocument.getInstance().fireResize();
};
Ext.extend(jsw.BrowserDocument, jsw.JComponent,{
		visible:false,
		//wrapperDom:document.body, WRONG: at this time, document.body has not been initialized by browser yet
		getClassName:function(){
			return "jsw.BrowserDocument";
		},
		fireResize:function(){
			this.width=document.body.clientWidth;
			this.height=document.body.clientHeight;		   
			this.revalidate();
		},
		paint:function(dirtyAttrs){
			if(this.foreground!=null)
				document.body.style.color=this.foreground;
			if(this.background!=null){
				document.body.bgColor=this.background;
			}
			this.paintComponent(document.body,dirtyAttrs);
			this._paintChildren(document.body);
		},
		isWindow:function(){
				return true;
		},
		paintComponent:function(dom, dirtyAttrs){
				if(this.background!=null && (dirtyAttrs==null || dirtyAttrs["backgdCl"])){
						document.body.bgColor=this.background;
				}
				if(this.backgroundImg!=null && ( dirtyAttrs==null || dirtyAttrs["backgdImg"])){
						document.body.background=this.backgroundImg;
				}
				
		},
		//@Overrider
		isValidateRoot:function(){
			return true;
		},
		//@Override
		revalidate:function(){		
			//jsw.debug(this.getClassName()+".revalidate()");
				this.invalidate();
				var rpmgr=jsw.RepaintManager.currentManager(this);
				//jsw.debug(this.getClassName()+".revalidate()-rpmgr.addInvalidComponent");
				rpmgr.addInvalidComponent(this);
				
		}
		
		//doLayout:function(){
		//	
		//	jsw.BrowserDocument.superclass.doLayout.apply(this,arguments);
		//}
});
jsw.BrowserDocument.instance=null;
jsw.BrowserDocument.getInstance=function(){
	if(jsw.BrowserDocument.instance == null)
		jsw.BrowserDocument.instance = new jsw.BrowserDocument();
	return jsw.BrowserDocument.instance;
}

jsw.FlowLayout=function(){
	var align, hgap, vgap;
	if(arguments.length<=0){
		align=jsw.FlowLayout.CENTER;
	}else{
		align=arguments[0];
	}
	if(arguments.length<=1){
		hgap=5;
	}else{
		hgap=arguments[1];
	}
	if(arguments.length<=2)
		vgap=5;
	else
		vgap=arguments[2];

	this.hgap = hgap;
	this.vgap = vgap;
	this.setAlignment(align);
};
jsw.FlowLayout.LEFT=0;
jsw.FlowLayout.CENTER=1;
jsw.FlowLayout.RIGHT=2;
jsw.FlowLayout.LEADING=3;
jsw.FlowLayout.TRAILING=4;
Ext.extend(jsw.FlowLayout, jsw.LayoutManager,
	{
		align:0,
		newAlign:0,
		hgap:0,
		vgap:0,
		alignOnBaseline:false,
		getAlignment:function(){
			return this.newAlign;
		},
		setAlignment:function(align){
			this.newAlign=align;
			switch (align) {
			case jsw.FlowLayout.LEADING:
				this.align = LEFT;
				break;
			case jsw.FlowLayout.TRAILING:
				this.align = RIGHT;
				break;
			default:
				this.align = align;
				break;
			}
		},
		getHgap:function(){
			return this.hgap;
		},
		setHgap:function(hgap){
			this.hgap = hgap;
		},
		getVgap:function() {
			return this.vgap;
		},
		setVgap:function(vgap) {
			this.vgap = vgap;
		},
		setAlignOnBaseline:function(alignOnBaseline) {
			this.alignOnBaseline = alignOnBaseline;
		},
		getAlignOnBaseline:function() {
			return this.alignOnBaseline;
		},
		addLayoutComponent:function(name, comp){},
		removeLayoutComponent:function(comp){},
		preferredLayoutSize:function(target){
			var dim={width:0,height:0};
			var nmembers = target.getComponentCount();
			var firstVisibleComponent = true;
			var useBaseline = this.getAlignOnBaseline();
			var maxAscent = 0;
			var maxDescent = 0;
			for (var i = 0 ; i < nmembers ; i++) {
				var m = target.getComponent(i);
				if (m.isVisible()) {
					var d = m.getPreferredSize();
					dim.height = Math.max(dim.height, d.height);
					if (firstVisibleComponent) {
						firstVisibleComponent = false;
					} else {
						dim.width += this.hgap;
					}
					dim.width += d.width;
					if (useBaseline) {
						var baseline = m.getBaseline(d.width, d.height);
						if (baseline >= 0) {
							maxAscent = Math.max(maxAscent, baseline);
							maxDescent = Math.max(maxDescent, d.height - baseline);
						}
					}
				}
			}
			if (useBaseline) {
				dim.height = Math.max(maxAscent + maxDescent, dim.height);
			}
			var insets = target.getInsets();
			dim.width += insets.left + insets.right + this.hgap*2;
			dim.height += insets.top + insets.bottom + this.vgap*2;
			return dim;
		},
		
		minimumLayoutSize:function(target) {
	  
			var useBaseline = this.getAlignOnBaseline();
			var dim = {width:0,height:0};
			var nmembers = target.getComponentCount();
			var maxAscent = 0;
			var maxDescent = 0;
			var firstVisibleComponent = true;

			for (var i = 0 ; i < nmembers ; i++) {
				var m = target.getComponent(i);
				if (m.visible) {
					var d = m.getMinimumSize();
					dim.height = Math.max(dim.height, d.height);
					if (firstVisibleComponent) {
						firstVisibleComponent = false;
					} else {
						dim.width += this.hgap;
					}
					dim.width += d.width;
					if (useBaseline) {
						var baseline = m.getBaseline(d.width, d.height);
						if (baseline >= 0) {
							maxAscent = Math.max(maxAscent, baseline);
							maxDescent = Math.max(maxDescent,
												  dim.height - baseline);
						}
					}
				}
			}

			if (useBaseline) {
				dim.height = Math.max(maxAscent + maxDescent, dim.height);
			}

			var insets = target.getInsets();
			dim.width += insets.left + insets.right + this.hgap*2;
			dim.height += insets.top + insets.bottom + this.vgap*2;
			return dim;
		},
		moveComponents:function(target, x, y, width, height,
								rowStart, rowEnd, ltr,
								useBaseline, ascent,
								descent) {
			switch (this.newAlign) {
				case jsw.FlowLayout.LEFT:
					x += ltr ? 0 : width;
					break;
				case jsw.FlowLayout.CENTER:
					x += width / 2;
					break;
				case jsw.FlowLayout.RIGHT:
					x += ltr ? width : 0;
					break;
				case jsw.FlowLayout.LEADING:
					break;
				case jsw.FlowLayout.TRAILING:
					x += width;
					break;
			}
			var maxAscent = 0;
			var nonbaselineHeight = 0;
			var baselineOffset = 0;
			if (useBaseline) {
				var maxDescent = 0;
				for (var i = rowStart ; i < rowEnd ; i++) {
					var m = target.getComponent(i);
					if (m.visible) {
						if (ascent[i] >= 0) {
							maxAscent = Math.max(maxAscent, ascent[i]);
							maxDescent = Math.max(maxDescent, descent[i]);
						}
						else {
							nonbaselineHeight = Math.max(m.getHeight(),
														 nonbaselineHeight);
						}
					}
				}
				height = Math.max(maxAscent + maxDescent, nonbaselineHeight);
				baselineOffset = (height - maxAscent - maxDescent) / 2;
			}
			for (var i = rowStart ; i < rowEnd ; i++) {
				var m = target.getComponent(i);
				if (m.isVisible()) {
					var cy;
					if (useBaseline && ascent[i] >= 0) {
						cy = y + baselineOffset + maxAscent - ascent[i];
					}
					else {
						cy = y + (height - m.height) / 2;
					}
					if (ltr) {
						m.setLocation(x, cy);
					} else {
						m.setLocation(target.width - x - m.width, cy);
					}
					x += m.width + this.hgap;
					
				}
			}
			return height;
		},
		
		layoutContainer:function(target) {
			
			var insets = target.getInsets();
			var maxwidth = target.width - (insets.left + insets.right + this.hgap*2);
			
			var nmembers = target.getComponentCount();
			var x = 0, y = insets.top + this.vgap;
			var rowh = 0, start = 0;
			
			var ltr = target.getComponentOrientation().isLeftToRight();
	
			var useBaseline = this.getAlignOnBaseline();
			var ascent = null;
			var descent = null;
	
			if (useBaseline) {
				ascent = [];
				descent = [];
			}
	
			for (var i = 0 ; i < nmembers ; i++) {
				var m = target.getComponent(i);
				if (m.isVisible()) {
					var d = m.getPreferredSize();
					m.setSize(d.width, d.height);
					
					if (useBaseline) {
						var baseline = m.getBaseline(d.width, d.height);
						if (baseline >= 0) {
							ascent[i] = baseline;
							descent[i] = d.height - baseline;
						}
						else {
							ascent[i] = -1;
						}
					}
					if ((x == 0) || ((x + d.width) <= maxwidth)) {
						if (x > 0) {
							x += this.hgap;
						}
						x += d.width;
						rowh = Math.max(rowh, d.height);
					} else {
						rowh = this.moveComponents(target, insets.left + this.hgap, y,
									   maxwidth - x, rowh, start, i, ltr,
									   useBaseline, ascent, descent);
						x = d.width;
						y += this.vgap + rowh;
						rowh = d.height;
						start = i;
					}
				}
			}
			this.moveComponents(target, insets.left + this.hgap, y, maxwidth - x, rowh,
						   start, nmembers, ltr, useBaseline, ascent, descent);
	  },
	  toString:function() {
			var str = "";
			switch (this.align) {
			  case jsw.FlowLayout.LEFT:		str = ",align=left"; break;
			  case jsw.FlowLayout.CENTER:	  str = ",align=center"; break;
			  case jsw.FlowLayout.RIGHT:	   str = ",align=right"; break;
			  case jsw.FlowLayout.LEADING:	 str = ",align=leading"; break;
			  case jsw.FlowLayout.TRAILING:	str = ",align=trailing"; break;
			}
			return "jsw.FlowLayout[hgap=" + this.hgap + ",vgap=" + this.vgap + str + "]";
		}
	});

jsw.ScrollLayout=function(){
	jsw.ScrollLayout.superclass.constructor.call(this,jsw.FlowLayout.CENTER,0,0);
	
};
Ext.extend(jsw.ScrollLayout, jsw.FlowLayout,{
		minimumLayoutSize:function(target) {
			var sz = target.getInsets();
			return {width: sz.left+sz.right};
		}
});


jsw.BoxLayout=function(target, axis){
			if (axis != jsw.BoxLayout.X_AXIS && axis != jsw.BoxLayout.Y_AXIS && 
			axis != jsw.BoxLayout.LINE_AXIS && axis != jsw.BoxLayout.PAGE_AXIS) {
			throw "Invalid axis";
		}
		this.axis = axis;
		this.target = target;
			this.xChildren=null;
			this.yChildren=null;
			this.xTotal=null;
			this.yTotal=null;
};
jsw.BoxLayout.X_AXIS = 0;
jsw.BoxLayout.Y_AXIS = 1;
jsw.BoxLayout.LINE_AXIS = 2;
jsw.BoxLayout.PAGE_AXIS = 3;
Ext.extend(jsw.BoxLayout,jsw.LayoutManager2,{
		getTarget:function() {
		return this.target;
	},
	getAxis:function(){
		return this.axis;
	},
	invalidateLayout:function(){
		this.checkContainer(this.target);
		this.xChildren = null;
		this.yChildren = null;
		this.xTotal = null;
		this.yTotal = null;
	},
	addLayoutComponent:function(name,comp) {
		this.invalidateLayout(comp.getParent());
	},
	removeLayoutComponent:function(comp) {
		this.invalidateLayout(comp.getParent());
	},
	addLayoutComponent:function(comp,constraints) {
		this.invalidateLayout(comp.getParent());
	},
	preferredLayoutSize:function(target) {
		var size;
		
		this.checkContainer(target);
		this.checkRequests();
		size = {width:this.xTotal.preferred, height:this.yTotal.preferred};
		

		var insets = target.getInsets();
		size.width = Math.min(size.width + insets.left + insets.right, 99999);
		size.height = Math.min(size.height + insets.top +insets.bottom, 99999);
		return size;
	},
	minimumLayoutSize:function(target) {
		var size;
		//synchronized(this) {
			this.checkContainer(target);
			this.checkRequests();
			size ={width:this.xTotal.minimum, height:this.yTotal.minimum};
		//}

		var insets = target.getInsets();
		size.width = Math.min(size.width + insets.left + insets.right, 99999);
		size.height =Math.min(size.height + insets.top + insets.bottom, 99999);
		return size;
	},
	maximumLayoutSize:function(target) {
		var size;
		//synchronized(this) {
			this.checkContainer(target);
			this.checkRequests();
			size = {width:this.xTotal.maximum, height:this.yTotal.maximum};
		//}

		var insets = target.getInsets();
		size.width =  Math.min(size.width + insets.left + insets.right, 99999);
		size.height = Math.min(size.height +  insets.top + insets.bottom, 99999);
		return size;
	},
	getLayoutAlignmentX:function(target) {
		this.checkContainer(target);
		this.checkRequests();
		return this.xTotal.alignment;
	},
	getLayoutAlignmentY:function(target) {
		this.checkContainer(target);
		this.checkRequests();
		return this.yTotal.alignment;
	},
	layoutContainer:function(target) {
		this.checkContainer(target);
		var nChildren = target.getComponentCount();
		xOffsets = new Array(nChildren);
		xSpans = new Array(nChildren);
		yOffsets = new Array(nChildren);
		ySpans = new Array(nChildren);
			
		var alloc = target.getSize();
		var insets = target.getInsets();
		alloc.width -= insets.left + insets.right;
		alloc.height -= insets.top + insets.bottom;

		// Resolve axis to an absolute value (either X_AXIS or Y_AXIS)
		var o = target.getComponentOrientation();
		var absoluteAxis = this.resolveAxis( this.axis, o );
		var ltr = (absoluteAxis != this.axis) ? o.isLeftToRight() : true;


		// determine the child placements
		//synchronized(this) {
			this.checkRequests();
		
			if (absoluteAxis == jsw.BoxLayout.X_AXIS) {
				jsw.SizeRequirements.calculateTiledPositions(alloc.width, this.xTotal,
														 this.xChildren, xOffsets,
														 xSpans, ltr);
				jsw.SizeRequirements.calculateAlignedPositions(alloc.height, this.yTotal,
														   this.yChildren, yOffsets,
														   ySpans);
			} else {
				jsw.SizeRequirements.calculateAlignedPositions(alloc.width, this.xTotal,
														   this.xChildren, xOffsets,
														   xSpans, ltr);
				
				jsw.SizeRequirements.calculateTiledPositions(alloc.height, this.yTotal,
														 this.yChildren, yOffsets,
														 ySpans);
				
			}
		

		// flush changes to the container
		for (var i = 0; i < nChildren; i++) {
			var c = target.getComponent(i);
			c.setBounds( Math.min( insets.left + xOffsets[i], 99999),
						Math.min( insets.top + yOffsets[i], 99999),
						xSpans[i], ySpans[i]);
			if(jsw.isDebugEnabled()){
				jsw.debug("jsw.BoxLayout.layoutContainer() setbounds w="+xSpans[i]+" h="+ySpans[i]);
			}
		}
		//if (this.dbg != null) {
		//	for (var i = 0; i < nChildren; i++) {
		//		var c = target.getComponent(i);
		//		dbg.println(c.toString());
		//		dbg.println("X: " + this.xChildren[i]);
		//		dbg.println("Y: " + this.yChildren[i]);
		//	}
		//}
			
	},
	checkContainer:function(target) {
		if (this.target != target) {
			throw "BoxLayout can't be shared";
		}
	},
	checkRequests:function(){
		if (this.xChildren == null || this.yChildren == null) {
			// The requests have been invalidated... recalculate
			// the request information.
			var n = this.target.getComponentCount();
			this.xChildren = [];
			this.yChildren = [];
			for (var i = 0; i < n; i++) {
				var c = this.target.getComponent(i);
				if (!c.isVisible()) {
					this.xChildren[i] = new jsw.SizeRequirements(0,0,0, c.getAlignmentX());
					this.yChildren[i] = new jsw.SizeRequirements(0,0,0, c.getAlignmentY());
					continue;
				}
				var min = c.getMinimumSize();
				var typ = c.getPreferredSize();
				var max = c.getMaximumSize();
				this.xChildren[i] = new jsw.SizeRequirements(min.width, typ.width, 
													max.width, 
													c.getAlignmentX());
				this.yChildren[i] = new jsw.SizeRequirements(min.height, typ.height, 
													max.height, 
													c.getAlignmentY());
			}
			
			// Resolve axis to an absolute value (either X_AXIS or Y_AXIS)
			var absoluteAxis = this.resolveAxis(this.axis,this.target.getComponentOrientation());

			if (absoluteAxis == jsw.BoxLayout.X_AXIS) {
				this.xTotal = jsw.SizeRequirements.getTiledSizeRequirements(this.xChildren);
				this.yTotal = jsw.SizeRequirements.getAlignedSizeRequirements(this.yChildren);
			} else {
				this.xTotal = jsw.SizeRequirements.getAlignedSizeRequirements(this.xChildren);
				this.yTotal = jsw.SizeRequirements.getTiledSizeRequirements(this.yChildren);
			}
		}
	},
	resolveAxis:function(axis, o ) {
		var absoluteAxis;
		if( axis == jsw.BoxLayout.LINE_AXIS ) {
			absoluteAxis = o.isHorizontal() ? jsw.BoxLayout.X_AXIS : jsw.BoxLayout.Y_AXIS;
		} else if( axis == jsw.BoxLayout.PAGE_AXIS ) {
			absoluteAxis = o.isHorizontal() ? jsw.BoxLayout.Y_AXIS : jsw.BoxLayout.X_AXIS;
		} else {
			absoluteAxis = axis;
		} 
		return absoluteAxis;
   }
});

jsw.SizeRequirements=function(min, pref, max, a){
	if(arguments.length==0){
		this.minimum=0;
		this.preferred=0;
		this.maximum=0;
		this.alignment=0.5;
	}else{
		this.minimum = min;
		this.preferred = pref;
		this.maximum = max;
		this.alignment = a > 1.0 ? 1.0 : a < 0.0 ? 0.0 : a;
	}
};
jsw.SizeRequirements.getTiledSizeRequirements=function(children){
		var total = new jsw.SizeRequirements();
		for (var i = 0; i < children.length; i++) {
			var req = children[i];
			total.minimum = Math.min(total.minimum +  req.minimum, 99999);
			total.preferred = Math.min( total.preferred +  req.preferred, 99999);
			total.maximum = Math.min( total.maximum +  req.maximum, 99999);
		}
		return total;
};
jsw.SizeRequirements.getAlignedSizeRequirements=function(children){
	var totalAscent = new jsw.SizeRequirements();
		var totalDescent = new jsw.SizeRequirements();
		for (var i = 0; i < children.length; i++) {
			var req = children[i];

			var ascent = (req.alignment * req.minimum);
			var descent = req.minimum - ascent;
			totalAscent.minimum = Math.max(ascent, totalAscent.minimum);
			totalDescent.minimum = Math.max(descent, totalDescent.minimum);

			ascent =  (req.alignment * req.preferred);
			descent = req.preferred - ascent;
			totalAscent.preferred = Math.max(ascent, totalAscent.preferred);
			totalDescent.preferred = Math.max(descent, totalDescent.preferred);

			ascent =(req.alignment * req.maximum);
			descent = req.maximum - ascent;
			totalAscent.maximum = Math.max(ascent, totalAscent.maximum);
			totalDescent.maximum = Math.max(descent, totalDescent.maximum);
		}
		var min = Math.min( totalAscent.minimum +  totalDescent.minimum, 99999);
		var pref = Math.min( totalAscent.preferred +  totalDescent.preferred, 99999);
		var max = Math.min( totalAscent.maximum +  totalDescent.maximum, 99999);
		var alignment = 0.0;
		if (min > 0) {
			alignment = totalAscent.minimum / min;
			alignment = alignment > 1.0 ? 1.0 : alignment < 0.0 ? 0.0 : alignment;
		}
		if(jsw.isDebugEnabled()){
			jsw.debug("SizeRequirements.getAlignedSizeRequirements\nalignment="+alignment
				+" component's alignment="+req.alignment+" req.minimum"+req.minimum+ " min="+min);
		}
		return new jsw.SizeRequirements(min, pref, max, alignment);
};
//jsw.SizeRequirements.calculateTiledPositions=function( allocated, total, children,offsets,spans) {
//		jsw.SizeRequirements._calculateTiledPositions(allocated, total, children, offsets, spans, true);
//};
jsw.SizeRequirements.calculateTiledPositions=function(allocated,total, children, offsets, spans, forward){
	if(typeof(forward)=="undefined") forward=true;
	var min = 0;
		var pref = 0;
		var max = 0;
		for (var i = 0; i < children.length; i++) {
			min += children[i].minimum;
			pref += children[i].preferred;
			max += children[i].maximum;
			if(jsw.isDebugEnabled()){
				jsw.debug("jsw.SizeRequirements.calculateTiledPositions()\n\tchild min="+children[i].minimum
					+"\n\tpref="+children[i].preferred+"\n\tmax="+children[i].maximum);
			}
		}
		if(jsw.isDebugEnabled()){
				jsw.debug("jsw.SizeRequirements.calculateTiledPositions()\n\tallocated="+allocated
					+" pref="+pref);
		}
		if (allocated >= pref) {
			jsw.SizeRequirements.expandedTile(allocated, min, pref, max, children, offsets, spans, forward);
			
		} else {
			jsw.SizeRequirements.compressedTile(allocated, min, pref, max, children, offsets, spans, forward);
		}
		
};
jsw.SizeRequirements.compressedTile=function(allocated, min, pref, max,
request,
offsets, spans,
forward) {
		if(typeof(forward)=="undefined") forward=true;
		var totalPlay = Math.min(pref - allocated, pref - min);
		var factor = (pref - min == 0) ? 0.0 : totalPlay / (pref - min);

		// ---- make the adjustments ----
		var totalOffset;
		if( forward ) {
			// lay out with offsets increasing from 0
			totalOffset = 0;
			for (var i = 0; i < spans.length; i++) {
				offsets[i] = totalOffset;
				var req = request[i];
				var play = factor * (req.preferred - req.minimum);
				spans[i] = (req.preferred - play);
				totalOffset =  Math.min( totalOffset + spans[i],99999);
			}
		} else {
			// lay out with offsets decreasing from the end of the allocation
			totalOffset = allocated;
			for (var i = 0; i < spans.length; i++) {
				var req = request[i];
				var play = factor * (req.preferred - req.minimum);
				spans[i] = (req.preferred - play);
				offsets[i] = totalOffset - spans[i];
				totalOffset =  Math.max(totalOffset - spans[i], 0);
			}
		}
};

jsw.SizeRequirements.expandedTile=function(allocated, min,  pref,  max,
									  request,
									  offsets,  spans,
									  forward)
{
	var totalPlay = Math.min(allocated - pref, max - pref);
		var factor = (max - pref == 0) ? 0.0 : totalPlay / (max - pref);

		// ---- make the adjustments ----
		var totalOffset;
		if( forward ) {
			// lay out with offsets increasing from 0
			totalOffset = 0;
			for (var i = 0; i < spans.length; i++) {
				offsets[i] = totalOffset;
				var req = request[i];
				var play = (factor * (req.maximum - req.preferred));
				spans[i] =  Math.min( req.preferred +  play, 99999);
				totalOffset =  Math.min( totalOffset +  spans[i],99999);
			}
		} else {
			// lay out with offsets decreasing from the end of the allocation
			totalOffset = allocated;
			for (var i = 0; i < spans.length; i++) {
				var req = request[i];
				var play = (factor * (req.maximum - req.preferred));
				spans[i] =  Math.min( req.preferred + play,99999);
				offsets[i] = totalOffset - spans[i];
				totalOffset =  Math.max(totalOffset -  spans[i], 0);
			}
		}
};

jsw.SizeRequirements.calculateAlignedPositions=function(allocated,
												 total,
												  children,
												  offsets,
												  spans,
												 normal) {
		if(normal==null) normal=true;
		var totalAlignment = normal ? total.alignment : 1.0 - total.alignment;
		var totalAscent = (allocated * totalAlignment);
		var totalDescent = allocated - totalAscent;
		for (var i = 0; i < children.length; i++) {
			var req = children[i];
			var alignment = normal ? req.alignment : 1.0 - req.alignment;
			var maxAscent = (req.maximum * alignment);
			var maxDescent = req.maximum - maxAscent;
			var ascent = Math.min(totalAscent, maxAscent);
			var descent = Math.min(totalDescent, maxDescent);
			
			offsets[i] = totalAscent - ascent;
			spans[i] =  Math.min(ascent + descent,99999);
			if(jsw.isDebugEnabled()){
				jsw.debug("SizeRequirements.calculateAlignedPositions\n\tspan[i]"+spans[i]
					+" total.alignment="+total.alignment
					+" allocated="+allocated+" totalAlignment="+totalAlignment
					+"\nalignment="+alignment+" req.maximum="+req.maximum
					+" totalAscent="+totalAscent+" maxAscent="+maxAscent
					+ " totalDescent="+totalDescent+" maxDescent="+maxDescent);
			}
		}	 
	};
jsw.SizeRequirements.adjustSizes=function(delta, children) {
	  return [];
	};
jsw.SizeRequirements.prototype={
	toString:function(){
		return "[" + this.minimum + "," + this.preferred + "," + this.maximum + "]@" + this.alignment;
	},
	getTiledSizeRequirements:jsw.SizeRequirements.getTiledSizeRequirements,
	getTiledSizeRequirements:jsw.SizeRequirements.getTiledSizeRequirements,
	//calculateTiledPositions:jsw.SizeRequirements.calculateTiledPositions,
	calculateTiledPositions:jsw.SizeRequirements.calculateTiledPositions,
	compressedTile:jsw.SizeRequirements.compressedTile,
	expandedTile:jsw.SizeRequirements.expandedTile,
	calculateAlignedPositions:jsw.SizeRequirements.calculateAlignedPositions,
	//calculateAlignedPositions:jsw.SizeRequirements.calculateAlignedPositions,
	adjustSizes:jsw.SizeRequirements.adjustSizes
};

jsw.Box=function(axis) {
		jsw.Box.superclass.constructor.call(this);
		jsw.Box.superclass.setLayout.call(this,new BoxLayout(this, axis));
};
jsw.Box.createHorizontalBox=function(){
	return new jsw.Box(jsw.BoxLayout.X_AXIS);
};
jsw.Box.createVerticalBox=function() {
		return new jsw.Box(jsw.BoxLayout.Y_AXIS);
};
jsw.Box.createRigidArea=function(d) {
		return new jsw.Box.Filler(d, d, d);
};
jsw.Box.createHorizontalStrut=function(width) {
	return new jsw.Box.Filler({width:width,height:0}, {width:width,height:0}, 
		{width:width, height:Short.MAX_VALUE});
};
jsw.Box.createVerticalStrut=function(height) {
	return new jsw.Box.Filler({width:0,height:height}, {width:0,height:height}, 
		{width:Short.MAX_VALUE, height:height});
};
jsw.Box.createHorizontalGlue=function() {
		return new jsw.Box.Filler({width:0,height:0}, {width:0,height:0}, 
			{width:Short.MAX_VALUE, height:0});
	}
jsw.Box.createGlue=function() {
	return new jsw.Box.Filler({width:0,height:0}, {width:0,height:0}, 
		{width:Short.MAX_VALUE, height:Short.MAX_VALUE});
};
jsw.Box.createVerticalGlue=function() {
		return new jsw.Box.Filler({width:0,height:0}, {width:0,height:0}, 
			{width:0, height:Short.MAX_VALUE});
};
Ext.extend(jsw.Box, jsw.JComponent,
	{
		paintComponent:function(c,dirtyAttrs) {
			if (this.ui != null) {
				// On the off chance some one created a UI, honor it
				jsw.Box.superclass.paintComponent.apply(this,arguments);
			} else if (this.isOpaque()) {
				if(this.background!=null)
					wrapperDom.style.backgroundColor=this.background;
			}
		}
	});
jsw.Box.Filler=function(min, pref, max) {
	jsw.Box.Filler.superclass.constructor.call(this);
			this.setMinimumSize(min);
			this.setPreferredSize(pref);
			this.setMaximumSize(max);
			this.setBackground('black');
		};
Ext.extend(jsw.Box.Filler, jsw.JComponent,
{
	changeShape:function( min,  pref,  max) {
			this.setMinimumSize(min);
			this.setPreferredSize(pref);
			this.setMaximumSize(max);
			this.revalidate();
		},
		paintComponent:function(wrapperDom, dirtyAttrs) {
			if (this.ui != null) {
				// On the off chance some one created a UI, honor it
				jsw.Box.Filler.superclass.paintComponent.apply(this,arguments);
			} else if (this.isOpaque()) {
				if(this.background!=null)
							wrapperDom.style.backgroundColor=this.background;
			}
		},
		getAccessibleContext:function() {
			//Todo:accessible
			//if (this.accessibleContext == null) {
				//this.accessibleContext = new AccessibleBoxFiller();
			//}
			//return this.accessibleContext;
		}
});

jsw.border.ShadowBorder=function(title){
		var imgDir=jsw.ROOT_DIR+'/js/img/ui/window/simple1/';
		this.borderData=[
				{w:17,h:17,url:imgDir+'BorderTopLeft.png'},
				{h:17,url:imgDir+'BorderTop.png'},
				{w:23,h:17,url:imgDir+'BorderTopRight.png'},
				{w:17,url:imgDir+'BorderLeft.png'},
						//tl:{w:'17',h:'17',url:imgDir+'BorderTopLeft.png'},
				{w:23,url:imgDir+'BorderRight.png'},
				{w:17,h:23,url:imgDir+'BorderBottomLeft.png'},
				{h:23,url:imgDir+'BorderBottom.png'},
				{w:23,h:23,url:imgDir+'BorderBottomRight.png'}
		];
		this.contentDomStyle={top:8,left:8,right:14,bottom:14,imgUrl:jsw.ROOT_DIR+"/js/img/ui/tran-red.png"};
		this.titleDomStyle={h:23,imgUrl:imgDir+"Header.png",color:"#e0e0e0",paddingLeft:"10"};
		this.setTitle(title);
		this.minimumSize={width:40,height:40};
		//this.minHeight=this.borderData[0].h+this.borderData[5].h+1;
};
Ext.extend(jsw.border.ShadowBorder, jsw.border.AbstractBorder,{
		rendered:false,
		containerEl:null,
		contentDom:null,
		
		getMinimumPaintSize:function(){
				return this.minimumSize;
		},
		getBorderInsets:function(c){
				return {top:8,left:8,right:14,bottom:14};
		},
		
		paintBorder:function(c, dom){
				var height = c.getHeight();
				var width = c.getWidth();
				var minis = this.getMinimumPaintSize();
				if(width<=minis.width || height<=minis.height){
						return;
				}
				//if(height < this.minHeight){
				//	throw new Exception("jsw.border.ShadowBorder: height "+height+" is too small, minimum height is "+this.minHeight);
				//		//height = this.minHeight;
				//}
				if(!this.rendered){						
						this._paintBorder(width,height,dom);
				}else{
						this.setSize(width,height);
				}
		},
		
		isBorderOpaque:function(){return false;},
		
		_paintBorder:function(width,height,containerDom){
				
				//for IE, must set this, otherwise we can't resize it to a smaller size,
				//if it has already contained some children doms
				var root=containerDom;
				var borderDoms=[];
				for(var i=0;i<8;i++){
						var cell=document.createElement('div');
						borderDoms.push(cell);
						cell.style.position="absolute";
						cell.style.overflow="hidden";//for IE6 must add, otherwise DIV will have a minimum height 19px
						
						var d=this.borderData[i];
						if(Ext.isIE6){
								cell.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='"+
										d.url+"')";
						}
						else{
								cell.style.background="url("+d.url+")";
						}
						
						root.appendChild(cell);
				}
				
				this.wrapDom=root;
				// todo: support "title"
				/*				
				if(this.title){
						this.titleDom=document.createElement('div');
						tst=this.titleDom.style;
						tst.position='relative';
						tst.overflow="hidden";
						tst.height=this.titleDomStyle.h+'px';
						for(var name in this.titleDomStyle){
								if(typeof(this.titleDomStyle[name])!='number'){
										tst[name]=this.titleDomStyle[name];
								}
						}
						this.titleDom.appendChild(document.createTextNode(this.title));		
						this.contentDom.appendChild(this.titleDom);
				}*/
				this.borderDoms=borderDoms;
				this.rendered=true;
				
				this.setSize(width,height);
		},
		setSize:function(width,height){
				//if(height<this.minHeight || width<=0){
				//		alert("invalid width or height:"+width+", "+height);
				//		throw new Exception("invalid width or height:"+width+", "+height);
				//}
				this.wrapDom.style.width=width+'px';
				this.wrapDom.style.height=height+'px';
				
				var borderDoms=this.borderDoms;
				for(var i=0;i<8;i++){
						var cell=this.borderDoms[i];
						var d=this.borderData[i];
						if(i>=0 && i<3){
								cell.style.top='0px';
						}
						if(i>=5 && i<8){
								cell.style.top=height-this.borderData[5].h+'px';
						}
						if(typeof(d.w)!='undefined'){
								cell.style.width=d.w+'px';
						}
						if(typeof(d.h)!='undefined'){
								cell.style.height=d.h+'px';
						}
				}
				borderDoms[0].style.left="0px";
				borderDoms[1].style.left=this.borderData[0].w+"px";
				
				borderDoms[1].style.width=width-this.borderData[0].w-this.borderData[2].w+"px";
				borderDoms[2].style.left=width-this.borderData[2].w+"px";
				
				borderDoms[3].style.left="0px";
				borderDoms[3].style.top=this.borderData[0].h+"px";
				borderDoms[3].style.height=height-this.borderData[0].h-this.borderData[5].h+"px";
				borderDoms[4].style.left=width-this.borderData[4].w+"px";
				borderDoms[4].style.top=this.borderData[2].h+"px";
				borderDoms[4].style.height=height-this.borderData[2].h-this.borderData[7].h+"px";
				
				borderDoms[5].style.left="0px";
				borderDoms[6].style.left=this.borderData[5].w+"px";				
				borderDoms[6].style.width=width-this.borderData[5].w-this.borderData[7].w+"px";
				borderDoms[7].style.left=width-this.borderData[7].w+"px";
				if(this.contentDom!=null){
						this.contentDom.style.left=this.contentDomStyle.left+"px";
						this.contentDom.style.top=this.contentDomStyle.top+"px";
						this.contentDom.style.width=width-this.contentDomStyle.left-this.contentDomStyle.right+"px";
						this.contentDom.style.height=height-this.contentDomStyle.top-this.contentDomStyle.bottom+"px";
				}
		},
		//onResize:function(){
		//		if(this.rendered){
		//				var width=this.containerEl.getWidth();
		//				var height=this.containerEl.getHeight();
		//				this.setSize(width,height);
		//		}
		//},
		setTitle:function(sText){
				this.title=sText;
		},
		getWrapDom:function(){
				return this.wrapDom;
		}
		
});

jsw.border.LineBorder=function(color, thickness){
	if(typeof(thickness)=="undefined")
		thickness=1;
	this.lineColor = color;
	this.thickness = thickness;
	this.rendered=false;
	this.useCssBorder=true;
};
Ext.extend(jsw.border.LineBorder,jsw.border.AbstractBorder,{
		
		paintBorder:function(c,wrapperDom){
			if(!this.rendered){
				var dom=document.createElement("div");
				wrapperDom.appendChild(dom);
				dom.style.border=this.thickness+"px solid "+this.lineColor;
				dom.style.overflow="hidden";
				dom.style.position="absolute";
				this.borderDom=dom;
				this.rendered=true;
			}
			if(Ext.isIE){
				this.borderDom.style.width=c.width+"px";
				this.borderDom.style.height=c.height+"px";
			}else{
				this.borderDom.style.width=c.width-(this.thickness<<1)+"px";
				this.borderDom.style.height=c.height-(this.thickness<<1)+"px";
			}
		},
		getBorderInsets:function(c,insets){
			if(typeof(insets)=="undefined"){
				insets={};
			}
			insets.left=this.thickness;
			insets.right=this.thickness;
			insets.top=this.thickness;
			insets.bottom=this.thickness;
			return insets;
		},
		getLineColor:function(){
			return this.lineColor;
		},
		getThickness:function(){
			return this.thickness;
		},
		isBorderOpaque:function(){
			return true;
		}
});

jsw.ImageIcon=function(url,desc){
	this.url=url;
	this.desc=desc;
	this.width=10;
	this.height=10;
	this.nativeHashCode=jsw.OBJECT_INDEX;
	jsw.OBJECT_INDEX++;
};
jsw.ImageIcon.prototype={
	getDescription:function() {
		return this.description;
	},
	getIconWidth:function() {
		return this.width;
	},
	 getIconHeight:function() {
		return this.height;
	},
	_loadImage:function(){
		var testDiv=jsw.ImageIcon.testDom;
		if(testDiv==null){
			testDiv=document.createElement("image");
			testDiv.style.position="absolute";
		  
			
			testDiv.style.zIndex="-191";
			testDiv.style.visibility="hidden";
			document.body.appendChild(testDiv);
			jsw.ImageIcon.testDom=testDiv;
		}
		if(this.url!=null){
			testDiv.src=this.url;
			var dim={width:dx+testDiv.clientWidth
			,height:dy+testDiv.clientHeight};
			return dim;
		}else{
			return {width:dx,height:dy};
		}
	}
};


